Skip to content

Commit

Permalink
fix: consecutive blockquotes blocks (#560)
Browse files Browse the repository at this point in the history
* fix: consecutive blockquotes blocks

* chore: tweak changeset and add the example from OP

---------

Co-authored-by: Evan Jacobs <570070+quantizor@users.noreply.github.com>
  • Loading branch information
frankie567 and quantizor committed Mar 22, 2024
1 parent 069b486 commit f5a0079
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .changeset/strange-planets-buy.md
@@ -0,0 +1,28 @@
---
"markdown-to-jsx": patch
---

fix: double newline between consecutive blockquote syntax creates separate blockquotes

Previously, for consecutive blockquotes they were rendered as one:

**Input**

```md
> Block A.1
> Block A.2

> Block B.1
```

**Output**

```html
<blockquote>
<p>Block A.1</p>
<p>Block A.2</p>
<p>Block.B.1</p>
</blockquote>
```

This is not compliant with the [GFM spec](https://github.github.com/gfm/#block-quotes) which states that consecutive blocks should be created if there is a blank line between them.
33 changes: 33 additions & 0 deletions index.compiler.spec.tsx
Expand Up @@ -563,6 +563,39 @@ describe('misc block level elements', () => {
</blockquote>
`)
})

it('should handle lazy continuation lines of blockquotes', () => {
render(compiler('> Line 1\nLine 2\n>Line 3'))

expect(root.innerHTML).toMatchInlineSnapshot(`
<blockquote>
<p>
Line 1
Line 2
Line 3
</p>
</blockquote>
`)
})

it('should handle consecutive blockquotes', () => {
render(compiler('> Something important, perhaps?\n\n> Something else'))

expect(root.innerHTML).toMatchInlineSnapshot(`
<div>
<blockquote>
<p>
Something important, perhaps?
</p>
</blockquote>
<blockquote>
<p>
Something else
</p>
</blockquote>
</div>
`)
})
})

describe('headings', () => {
Expand Down
2 changes: 1 addition & 1 deletion index.tsx
Expand Up @@ -177,7 +177,7 @@ const ATTR_EXTRACTOR_R =

const AUTOLINK_MAILTO_CHECK_R = /mailto:/i
const BLOCK_END_R = /\n{2,}$/
const BLOCKQUOTE_R = /^( *>[^\n]+(\n[^\n]+)*\n*)+\n{2,}/
const BLOCKQUOTE_R = /^(\s*>[\s\S]*?)(?=\n{2,})/
const BLOCKQUOTE_TRIM_LEFT_MULTILINE_R = /^ *> ?/gm
const BREAK_LINE_R = /^ {2,}\n/
const BREAK_THEMATIC_R = /^(?:( *[-*_])){3,} *(?:\n *)+\n/
Expand Down

0 comments on commit f5a0079

Please sign in to comment.