Skip to content

Commit

Permalink
fix: #641 (#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor authored Jan 7, 2025
1 parent 02c883b commit 8026103
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-bugs-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'markdown-to-jsx': patch
---

Handle paragraph splitting better, fixes #641.
50 changes: 50 additions & 0 deletions index.compiler.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2574,6 +2574,56 @@ describe('GFM tables', () => {
</table>
`)
})

it('#641 handles only a single newline prior to the start of the table', () => {
render(
compiler(theredoc`
Test
| Nested HTML | Link |
| ---------------------------------- | ---------------------------- |
| <div><strong>Nested</strong></div> | [I'm a \`link\`](www.google.com) |
`)
)

expect(root.innerHTML).toMatchInlineSnapshot(`
<div>
<p>
Test
</p>
<table>
<thead>
<tr>
<th>
Nested HTML
</th>
<th>
Link
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div>
<strong>
Nested
</strong>
</div>
</td>
<td>
<a href="www.google.com">
I'm a
<code>
link
</code>
</a>
</td>
</tr>
</tbody>
</table>
</div>
`)
})
})

describe('arbitrary HTML', () => {
Expand Down
8 changes: 6 additions & 2 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8026103

Please sign in to comment.