Skip to content

Commit

Permalink
fix: deep html nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor authored and Innei committed Mar 28, 2024
1 parent f3f61f7 commit 5657c71
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 @@ -3169,13 +3169,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 @@ -4158,6 +4158,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 @@ -429,7 +429,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 5657c71

Please sign in to comment.