From f5a0079c16a318e166199d2815631d18a0f3e6e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Voron?= Date: Fri, 22 Mar 2024 20:18:26 +0100 Subject: [PATCH] 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> --- .changeset/strange-planets-buy.md | 28 ++++++++++++++++++++++++++ index.compiler.spec.tsx | 33 +++++++++++++++++++++++++++++++ index.tsx | 2 +- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 .changeset/strange-planets-buy.md diff --git a/.changeset/strange-planets-buy.md b/.changeset/strange-planets-buy.md new file mode 100644 index 0000000..62dfd1c --- /dev/null +++ b/.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 +
+

Block A.1

+

Block A.2

+

Block.B.1

+
+``` + +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. diff --git a/index.compiler.spec.tsx b/index.compiler.spec.tsx index 69e053a..53950e8 100644 --- a/index.compiler.spec.tsx +++ b/index.compiler.spec.tsx @@ -563,6 +563,39 @@ describe('misc block level elements', () => { `) }) + + it('should handle lazy continuation lines of blockquotes', () => { + render(compiler('> Line 1\nLine 2\n>Line 3')) + + expect(root.innerHTML).toMatchInlineSnapshot(` +
+

+ Line 1 + Line 2 + Line 3 +

+
+ `) + }) + + it('should handle consecutive blockquotes', () => { + render(compiler('> Something important, perhaps?\n\n> Something else')) + + expect(root.innerHTML).toMatchInlineSnapshot(` +
+
+

+ Something important, perhaps? +

+
+
+

+ Something else +

+
+
+ `) + }) }) describe('headings', () => { diff --git a/index.tsx b/index.tsx index 62c8c79..898ad64 100644 --- a/index.tsx +++ b/index.tsx @@ -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/