Skip to content

Commit

Permalink
fix: deep html nesting
Browse files Browse the repository at this point in the history
Closes #520
  • Loading branch information
quantizor committed Mar 21, 2024
1 parent fd35402 commit 4f752c8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-deers-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"markdown-to-jsx": patch
---

Fix handling of deeply-nested HTML in some scenarios.
41 changes: 27 additions & 14 deletions index.compiler.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ describe('inline textual elements', () => {
render(compiler('**Hello\nWorld.**\n'))

expect(root.innerHTML).toMatchInlineSnapshot(`
<p>
<strong>
Hello
World.
</strong>
</p>
`)
<p>
<strong>
Hello
World.
</strong>
</p>
`)
})

it('should handle triple-emphasized text', () => {
Expand Down Expand Up @@ -3401,13 +3401,13 @@ Item detail
)

expect(root.innerHTML).toMatchInlineSnapshot(`
<p>
Item detail
<span style="color: rgb(253, 219, 103); font-size: 11px; font-style: normal; font-weight: 500; line-height: 18px; text-decoration-line: underline;">
debug item 1
</span>
</p>
`)
<p>
Item detail
<span style="color: rgb(253, 219, 103); font-size: 11px; font-style: normal; font-weight: 500; line-height: 18px; text-decoration-line: underline;">
debug item 1
</span>
</p>
`)
})
})

Expand Down Expand Up @@ -4342,6 +4342,19 @@ describe('overrides', () => {

expect(root.innerHTML).toMatchInlineSnapshot(`"test"`)
})

it('#520 handle deep nesting', () => {
render(compiler('<div><div><div></div></div></div>'))

expect(root.innerHTML).toMatchInlineSnapshot(`
<div>
<div>
<div>
</div>
</div>
</div>
`)
})
})

it('should remove YAML front matter', () => {
Expand Down
2 changes: 1 addition & 1 deletion index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ const HEADING_SETEXT_R = /^([^\n]+)\n *(=|-){3,} *(?:\n *)+\n/
* \n*
*/
const HTML_BLOCK_ELEMENT_R =
/^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?([^>]*)>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1\b)[\s\S])*?)<\/\1>\n*/i
/^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?([^>]*)>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1\b)[\s\S])*?)<\/\1>(?!<\/\1>)\n*/i

const HTML_CHAR_CODE_R = /&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/gi

Expand Down

0 comments on commit 4f752c8

Please sign in to comment.