Skip to content

Commit

Permalink
fix: handle render of empty noInnerParse html nodes like script and s…
Browse files Browse the repository at this point in the history
…tyle tag #597 (#601)

* fix: handle empty noInnerParse html nodes

* Create sharp-lobsters-turn.md

---------

Co-authored-by: Evan Jacobs <[email protected]>
  • Loading branch information
Antony0101 and quantizor authored Nov 12, 2024
1 parent b16f668 commit 58b96d3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sharp-lobsters-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"markdown-to-jsx": patch
---

fix: handle empty HTML tags more consistently #597
9 changes: 9 additions & 0 deletions index.compiler.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4711,3 +4711,12 @@ it('handles naked brackets in link text', () => {
</a>
`)
})

it('#597 handles script tag with empty content', () => {
render(compiler('<script src="dummy.js"></script>'))

expect(root.innerHTML).toMatchInlineSnapshot(`
<script src="dummy.js">
</script>
`)
})
2 changes: 1 addition & 1 deletion index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@ export function compiler(
render(node, output, state) {
return (
<node.tag key={state.key} {...node.attrs}>
{node.text || output(node.children, state)}
{node.text || (node.children ? output(node.children, state) : '')}
</node.tag>
)
},
Expand Down

0 comments on commit 58b96d3

Please sign in to comment.