Skip to content

Commit f5a0079

Browse files
frankie567quantizor
andauthoredMar 22, 2024··
fix: consecutive blockquotes blocks (#560)
* fix: consecutive blockquotes blocks * chore: tweak changeset and add the example from OP --------- Co-authored-by: Evan Jacobs <570070+quantizor@users.noreply.github.com>
1 parent 069b486 commit f5a0079

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed
 

‎.changeset/strange-planets-buy.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
"markdown-to-jsx": patch
3+
---
4+
5+
fix: double newline between consecutive blockquote syntax creates separate blockquotes
6+
7+
Previously, for consecutive blockquotes they were rendered as one:
8+
9+
**Input**
10+
11+
```md
12+
> Block A.1
13+
> Block A.2
14+
15+
> Block B.1
16+
```
17+
18+
**Output**
19+
20+
```html
21+
<blockquote>
22+
<p>Block A.1</p>
23+
<p>Block A.2</p>
24+
<p>Block.B.1</p>
25+
</blockquote>
26+
```
27+
28+
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.

‎index.compiler.spec.tsx

+33
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,39 @@ describe('misc block level elements', () => {
563563
</blockquote>
564564
`)
565565
})
566+
567+
it('should handle lazy continuation lines of blockquotes', () => {
568+
render(compiler('> Line 1\nLine 2\n>Line 3'))
569+
570+
expect(root.innerHTML).toMatchInlineSnapshot(`
571+
<blockquote>
572+
<p>
573+
Line 1
574+
Line 2
575+
Line 3
576+
</p>
577+
</blockquote>
578+
`)
579+
})
580+
581+
it('should handle consecutive blockquotes', () => {
582+
render(compiler('> Something important, perhaps?\n\n> Something else'))
583+
584+
expect(root.innerHTML).toMatchInlineSnapshot(`
585+
<div>
586+
<blockquote>
587+
<p>
588+
Something important, perhaps?
589+
</p>
590+
</blockquote>
591+
<blockquote>
592+
<p>
593+
Something else
594+
</p>
595+
</blockquote>
596+
</div>
597+
`)
598+
})
566599
})
567600

568601
describe('headings', () => {

‎index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ const ATTR_EXTRACTOR_R =
177177

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

0 commit comments

Comments
 (0)
Please sign in to comment.