Skip to content

Commit

Permalink
fix: html block regex prefix conflict (#558)
Browse files Browse the repository at this point in the history
Closes #530
  • Loading branch information
quantizor authored Mar 21, 2024
1 parent 3af166c commit fd35402
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/two-files-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"markdown-to-jsx": patch
---

Fix HTML block regex for custom component scenarios where a nested component shares the same prefix as the parent, e.g. Accordion vs AccordionItem.
13 changes: 13 additions & 0 deletions index.compiler.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4329,6 +4329,19 @@ describe('overrides', () => {
</div>
`)
})

it('#530 nested overrides', () => {
render(
compiler('<Accordion><AccordionItem>test</AccordionItem></Accordion>', {
overrides: {
Accordion: ({ children }) => children,
AccordionItem: ({ children }) => children,
},
})
)

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

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)[\s\S])*?)<\/\1>\n*/i
/^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?([^>]*)>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1\b)[\s\S])*?)<\/\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 fd35402

Please sign in to comment.