From 58b96d3cd0382004b6ab4c7ac64ba2080c4ed14a Mon Sep 17 00:00:00 2001 From: Antony0101 <59156570+Antony0101@users.noreply.github.com> Date: Tue, 12 Nov 2024 10:43:40 +0530 Subject: [PATCH] fix: handle render of empty noInnerParse html nodes like script and style tag #597 (#601) * fix: handle empty noInnerParse html nodes * Create sharp-lobsters-turn.md --------- Co-authored-by: Evan Jacobs <570070+quantizor@users.noreply.github.com> --- .changeset/sharp-lobsters-turn.md | 5 +++++ index.compiler.spec.tsx | 9 +++++++++ index.tsx | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/sharp-lobsters-turn.md diff --git a/.changeset/sharp-lobsters-turn.md b/.changeset/sharp-lobsters-turn.md new file mode 100644 index 00000000..f6c1afaf --- /dev/null +++ b/.changeset/sharp-lobsters-turn.md @@ -0,0 +1,5 @@ +--- +"markdown-to-jsx": patch +--- + +fix: handle empty HTML tags more consistently #597 diff --git a/index.compiler.spec.tsx b/index.compiler.spec.tsx index 26388e6a..b30376ac 100644 --- a/index.compiler.spec.tsx +++ b/index.compiler.spec.tsx @@ -4711,3 +4711,12 @@ it('handles naked brackets in link text', () => { `) }) + +it('#597 handles script tag with empty content', () => { + render(compiler('')) + + expect(root.innerHTML).toMatchInlineSnapshot(` + + `) +}) diff --git a/index.tsx b/index.tsx index e94e8762..e6a563a3 100644 --- a/index.tsx +++ b/index.tsx @@ -1546,7 +1546,7 @@ export function compiler( render(node, output, state) { return ( - {node.text || output(node.children, state)} + {node.text || (node.children ? output(node.children, state) : '')} ) },