Fix rich markdown editor HTML tag crashes

This commit is contained in:
Dotta committed 2026-04-24 07:36:35 -05:00
1 parent d020b08955
commit 2b032548cc
2 files changed
+27 -2

No files matched your search

+26 -2
View File
@@ -63,7 +63,7 @@ vi.mock("@mdxeditor/editor", async () => {
}), []);
React.useEffect(() => {
if (!suppressHtmlProcessing && markdown.includes("<img ")) {
if (!suppressHtmlProcessing && (markdown.includes("<img ") || markdown.includes("<gpt>"))) {
setContent("");
onError?.({
error: "Error parsing markdown: HTML-like formatting requires suppressHtmlProcessing",
@@ -251,7 +251,7 @@ describe("MarkdownEditor", () => {
await flush();
expect(mdxEditorMockState.markdownValues.at(-1)).toContain("![image](https://example.com/test.png)");
expect(mdxEditorMockState.markdownValues.at(-1)).not.toContain("<img");
expect(mdxEditorMockState.suppressHtmlProcessingValues).toContain(false);
expect(mdxEditorMockState.suppressHtmlProcessingValues).toContain(true);
expect(container.textContent).toContain("Before");
expect(container.textContent).toContain("After");
@@ -260,6 +260,30 @@ describe("MarkdownEditor", () => {
});
});
it("keeps LLM wrapper tags in the rich editor instead of falling back to raw source", async () => {
const root = createRoot(container);
await act(async () => {
root.render(
<MarkdownEditor
value={"<gpt>\n## My take\n\nBenchmark notes\n</gpt>"}
onChange={() => {}}
placeholder="Markdown body"
/>,
);
});
await flush();
expect(mdxEditorMockState.suppressHtmlProcessingValues).toContain(true);
expect(container.querySelector("textarea")).toBeNull();
expect(container.textContent).toContain("Benchmark notes");
expect(container.textContent).not.toContain("Rich editor unavailable for this markdown");
await act(async () => {
root.unmount();
});
});
it("falls back to a raw textarea when the rich parser rejects the markdown", async () => {
mdxEditorMockState.emitMountParseError = true;
const handleChange = vi.fn();
+1
View File
@@ -1082,6 +1082,7 @@ export const MarkdownEditor = forwardRef<MarkdownEditorRef, MarkdownEditorProps>
<MDXEditor
ref={setEditorRef}
markdown={editorValue}
suppressHtmlProcessing
placeholder={placeholder}
readOnly={readOnly}
onChange={(next) => {