diff --git a/.changeset/tidy-cheetahs-count.md b/.changeset/tidy-cheetahs-count.md new file mode 100644 index 00000000..63c58997 --- /dev/null +++ b/.changeset/tidy-cheetahs-count.md @@ -0,0 +1,5 @@ +--- +'markdown-to-jsx': patch +--- + +Arbitrary HTML no longer punches out pipes when parsing rows. If you absolutely need a pipe character that isn't a table separator, either escape it or enclose it in backticks to trigger inline code handling. diff --git a/index.compiler.spec.tsx b/index.compiler.spec.tsx index 02929239..2f10866e 100644 --- a/index.compiler.spec.tsx +++ b/index.compiler.spec.tsx @@ -2247,6 +2247,55 @@ describe('GFM tables', () => { `) }) + it('regression #625 - processes self-closing HTML inside of a table row', () => { + render( + compiler(theredoc` + | col1 | col2 | col3 | + |------|-----------------|------------------| + | col1 | col2
col2 | col3
col3 | + `) + ) + + expect(root.innerHTML).toMatchInlineSnapshot(` + + + + + + + + + + + + + + + +
+ col1 + + col2 + + col3 +
+ col1 + + + col2 + +
+ col2 +
+ + col3 + +
+ col3 +
+ `) + }) + it('processes markdown inside of a table row when a preceeding column contains HTML', () => { render( compiler(theredoc` diff --git a/index.tsx b/index.tsx index 445040e1..36fc6fe4 100644 --- a/index.tsx +++ b/index.tsx @@ -624,8 +624,8 @@ function parseTableRow( state.inTable = true let tableRow = source .trim() - // isolate situations where a pipe should be ignored (inline code, HTML) - .split(/( *(?:`[^`]*`|<.*?>.*?<\/.*?>(?!<\/.*?>)|\\\||\|) *)/) + // isolate situations where a pipe should be ignored (inline code, escaped, etc) + .split(/( *(?:`[^`]*`|\\\||\|) *)/) .reduce((nodes, fragment) => { if (fragment.trim() === '|') nodes.push(