From ebf0e820634b83f4609f0e799509acd836915feb Mon Sep 17 00:00:00 2001 From: Evan Jacobs Date: Wed, 20 Mar 2024 23:45:24 -0400 Subject: [PATCH] fix: html block regex prefix conflict Closes #530 --- .changeset/two-files-relate.md | 5 +++++ index.compiler.spec.tsx | 13 +++++++++++++ index.tsx | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .changeset/two-files-relate.md diff --git a/.changeset/two-files-relate.md b/.changeset/two-files-relate.md new file mode 100644 index 00000000..4871f8c7 --- /dev/null +++ b/.changeset/two-files-relate.md @@ -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. diff --git a/index.compiler.spec.tsx b/index.compiler.spec.tsx index 62659462..102be7ef 100644 --- a/index.compiler.spec.tsx +++ b/index.compiler.spec.tsx @@ -4329,6 +4329,19 @@ describe('overrides', () => { `) }) + + it('#530 nested overrides', () => { + render( + compiler('test', { + overrides: { + Accordion: ({ children }) => children, + AccordionItem: ({ children }) => children, + }, + }) + ) + + expect(root.innerHTML).toMatchInlineSnapshot(`"test"`) + }) }) it('should remove YAML front matter', () => { diff --git a/index.tsx b/index.tsx index 06974546..09ed18a4 100644 --- a/index.tsx +++ b/index.tsx @@ -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