diff --git a/.changeset/eleven-bugs-report.md b/.changeset/eleven-bugs-report.md new file mode 100644 index 0000000..b75b251 --- /dev/null +++ b/.changeset/eleven-bugs-report.md @@ -0,0 +1,5 @@ +--- +'markdown-to-jsx': patch +--- + +Handle paragraph splitting better, fixes #641. diff --git a/index.compiler.spec.tsx b/index.compiler.spec.tsx index 007f3a9..1bc9b95 100644 --- a/index.compiler.spec.tsx +++ b/index.compiler.spec.tsx @@ -2574,6 +2574,56 @@ describe('GFM tables', () => { `) }) + + it('#641 handles only a single newline prior to the start of the table', () => { + render( + compiler(theredoc` + Test + | Nested HTML | Link | + | ---------------------------------- | ---------------------------- | + |
Nested
| [I'm a \`link\`](www.google.com) | + `) + ) + + expect(root.innerHTML).toMatchInlineSnapshot(` +
+

+ Test +

+ + + + + + + + + + + + + +
+ Nested HTML + + Link +
+
+ + Nested + +
+
+ + I'm a + + link + + +
+
+ `) + }) }) describe('arbitrary HTML', () => { diff --git a/index.tsx b/index.tsx index d35018d..96f4b51 100644 --- a/index.tsx +++ b/index.tsx @@ -942,12 +942,16 @@ function matchParagraph(source: string, state: MarkdownToJSX.State) { let match = '' source.split('\n').every(line => { + line += '\n' + // bail out on first sign of non-paragraph block if (NON_PARAGRAPH_BLOCK_SYNTAXES.some(regex => regex.test(line))) { return false } - match += line + '\n' - return line.trim() + + match += line + + return !!line.trim() }) const captured = match.trimEnd()