diff --git a/.changeset/afraid-lobsters-complain.md b/.changeset/afraid-lobsters-complain.md new file mode 100644 index 0000000..6afb594 --- /dev/null +++ b/.changeset/afraid-lobsters-complain.md @@ -0,0 +1,5 @@ +--- +'markdown-to-jsx': patch +--- + +Fix false detection of tables in some scenarios. diff --git a/index.compiler.spec.tsx b/index.compiler.spec.tsx index d7296c8..0292923 100644 --- a/index.compiler.spec.tsx +++ b/index.compiler.spec.tsx @@ -756,6 +756,16 @@ describe('headings', () => { `) }) + + it('#595 regression - handle pipe character inside header', () => { + render(compiler('# Heading | text')) + + expect(root.innerHTML).toMatchInlineSnapshot(` +

+ Heading | text +

+ `) + }) }) describe('images', () => { @@ -1851,7 +1861,7 @@ describe('GFM tables', () => { it('should handle a basic table', () => { render( compiler(theredoc` - foo|bar + |foo|bar| ---|--- 1 |2 `) @@ -1886,7 +1896,7 @@ describe('GFM tables', () => { it('should handle a table with aligned columns', () => { render( compiler(theredoc` - foo|bar|baz + |foo|bar|baz| --:|:---:|:-- 1|2|3 `) diff --git a/index.tsx b/index.tsx index b238a63..445040e 100644 --- a/index.tsx +++ b/index.tsx @@ -273,8 +273,7 @@ const LINK_AUTOLINK_BARE_URL_R = /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/ const LINK_AUTOLINK_MAILTO_R = /^<([^ >]+@[^ >]+)>/ const LINK_AUTOLINK_R = /^<([^ >]+:\/[^ >]+)>/ const CAPTURE_LETTER_AFTER_HYPHEN = /-([a-z])?/gi -const NP_TABLE_R = - /^(.*\|.*)\n(?: *(\|? *[-:]+ *\|[-| :]*)\n((?:.*\|.*\n)*))?\n?/ +const NP_TABLE_R = /^(\|.*)\n(?: *(\|? *[-:]+ *\|[-| :]*)\n((?:.*\|.*\n)*))?\n?/ const PARAGRAPH_R = /^[^\n]+(?: \n|\n{2,})/ const REFERENCE_IMAGE_OR_LINK = /^\[([^\]]*)\]:\s+]+)>?\s*("([^"]*)")?/ const REFERENCE_IMAGE_R = /^!\[([^\]]*)\] ?\[([^\]]*)\]/ @@ -926,20 +925,11 @@ function anyScopeRegex(regex: RegExp) { } } -function matchParagraph( - source: string, - state: MarkdownToJSX.State, - prevCapturedString?: string -) { +function matchParagraph(source: string, state: MarkdownToJSX.State) { if (state.inline || state.simple) { return null } - if (prevCapturedString && !prevCapturedString.endsWith('\n')) { - // don't match continuation of a line - return null - } - let match = '' source.split('\n').every(line => {