Skip to content

Commit 4f752c8

Browse files
committedMar 21, 2024·
fix: deep html nesting
Closes #520
1 parent fd35402 commit 4f752c8

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed
 

‎.changeset/fuzzy-deers-argue.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"markdown-to-jsx": patch
3+
---
4+
5+
Fix handling of deeply-nested HTML in some scenarios.

‎index.compiler.spec.tsx

+27-14
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,13 @@ describe('inline textual elements', () => {
248248
render(compiler('**Hello\nWorld.**\n'))
249249

250250
expect(root.innerHTML).toMatchInlineSnapshot(`
251-
<p>
252-
<strong>
253-
Hello
254-
World.
255-
</strong>
256-
</p>
257-
`)
251+
<p>
252+
<strong>
253+
Hello
254+
World.
255+
</strong>
256+
</p>
257+
`)
258258
})
259259

260260
it('should handle triple-emphasized text', () => {
@@ -3401,13 +3401,13 @@ Item detail
34013401
)
34023402

34033403
expect(root.innerHTML).toMatchInlineSnapshot(`
3404-
<p>
3405-
Item detail
3406-
<span style="color: rgb(253, 219, 103); font-size: 11px; font-style: normal; font-weight: 500; line-height: 18px; text-decoration-line: underline;">
3407-
debug item 1
3408-
</span>
3409-
</p>
3410-
`)
3404+
<p>
3405+
Item detail
3406+
<span style="color: rgb(253, 219, 103); font-size: 11px; font-style: normal; font-weight: 500; line-height: 18px; text-decoration-line: underline;">
3407+
debug item 1
3408+
</span>
3409+
</p>
3410+
`)
34113411
})
34123412
})
34133413

@@ -4342,6 +4342,19 @@ describe('overrides', () => {
43424342

43434343
expect(root.innerHTML).toMatchInlineSnapshot(`"test"`)
43444344
})
4345+
4346+
it('#520 handle deep nesting', () => {
4347+
render(compiler('<div><div><div></div></div></div>'))
4348+
4349+
expect(root.innerHTML).toMatchInlineSnapshot(`
4350+
<div>
4351+
<div>
4352+
<div>
4353+
</div>
4354+
</div>
4355+
</div>
4356+
`)
4357+
})
43454358
})
43464359

43474360
it('should remove YAML front matter', () => {

‎index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ const HEADING_SETEXT_R = /^([^\n]+)\n *(=|-){3,} *(?:\n *)+\n/
254254
* \n*
255255
*/
256256
const HTML_BLOCK_ELEMENT_R =
257-
/^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?([^>]*)>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1\b)[\s\S])*?)<\/\1>\n*/i
257+
/^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?([^>]*)>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1\b)[\s\S])*?)<\/\1>(?!<\/\1>)\n*/i
258258

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

0 commit comments

Comments
 (0)
Please sign in to comment.