Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #641 #648

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading