From e9f0eed707ece9e29c3bf340900d1acb42acaddd Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 18 Apr 2024 23:06:58 -0600 Subject: [PATCH] fix: fix Setext continuation in blockquote (#3257) --- src/Tokenizer.ts | 4 +++- src/rules.ts | 4 ++-- test/specs/commonmark/commonmark.0.31.json | 3 +-- test/specs/gfm/commonmark.0.31.json | 3 +-- test/specs/new/blockquote_setext.html | 19 +++++++++++++++++++ test/specs/new/blockquote_setext.md | 16 ++++++++++++++++ test/specs/new/setext_no_blankline.html | 2 -- test/specs/new/setext_no_blankline.md | 3 --- 8 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 test/specs/new/blockquote_setext.html create mode 100644 test/specs/new/blockquote_setext.md diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index 9daee0b6..10b31454 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -156,7 +156,9 @@ export class _Tokenizer { blockquote(src: string): Tokens.Blockquote | undefined { const cap = this.rules.block.blockquote.exec(src); if (cap) { - const text = rtrim(cap[0].replace(/^ *>[ \t]?/gm, ''), '\n'); + // precede setext continuation with 4 spaces so it isn't a setext + let text = cap[0].replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g, '\n $1'); + text = rtrim(text.replace(/^ *>[ \t]?/gm, ''), '\n'); const top = this.lexer.state.top; this.lexer.state.top = true; const tokens = this.lexer.blockTokens(text); diff --git a/src/rules.ts b/src/rules.ts index cd6baf90..07f0990e 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -58,7 +58,7 @@ const html = edit( const paragraph = edit(_paragraph) .replace('hr', hr) .replace('heading', ' {0,3}#{1,6}(?:\\s|$)') - .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs + .replace('|lheading', '') // setext headings don't interrupt commonmark paragraphs .replace('|table', '') .replace('blockquote', ' {0,3}>') .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n') @@ -117,7 +117,7 @@ const blockGfm: Record = { paragraph: edit(_paragraph) .replace('hr', hr) .replace('heading', ' {0,3}#{1,6}(?:\\s|$)') - .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs + .replace('|lheading', '') // setext headings don't interrupt commonmark paragraphs .replace('table', gfmTable) // interrupt paragraphs with table .replace('blockquote', ' {0,3}>') .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n') diff --git a/test/specs/commonmark/commonmark.0.31.json b/test/specs/commonmark/commonmark.0.31.json index 1fdabe7b..f9b5db2e 100644 --- a/test/specs/commonmark/commonmark.0.31.json +++ b/test/specs/commonmark/commonmark.0.31.json @@ -743,8 +743,7 @@ "example": 93, "start_line": 1527, "end_line": 1537, - "section": "Setext headings", - "shouldFail": true + "section": "Setext headings" }, { "markdown": "- Foo\n---\n", diff --git a/test/specs/gfm/commonmark.0.31.json b/test/specs/gfm/commonmark.0.31.json index 7e7421ff..ff36b9f4 100644 --- a/test/specs/gfm/commonmark.0.31.json +++ b/test/specs/gfm/commonmark.0.31.json @@ -743,8 +743,7 @@ "example": 93, "start_line": 1527, "end_line": 1537, - "section": "Setext headings", - "shouldFail": true + "section": "Setext headings" }, { "markdown": "- Foo\n---\n", diff --git a/test/specs/new/blockquote_setext.html b/test/specs/new/blockquote_setext.html new file mode 100644 index 00000000..313d6acc --- /dev/null +++ b/test/specs/new/blockquote_setext.html @@ -0,0 +1,19 @@ +
+

not heading 1 ==

+
+ +
+

not heading 2 --

+
+ +
+

heading 1

+
+ +
+

heading 2

+
+ +
+

not heading 1 == not heading 2 with br
--

+
diff --git a/test/specs/new/blockquote_setext.md b/test/specs/new/blockquote_setext.md new file mode 100644 index 00000000..0b164a91 --- /dev/null +++ b/test/specs/new/blockquote_setext.md @@ -0,0 +1,16 @@ +> not heading 1 +== + +> not heading 2 +-- + +> heading 1 +> == + +> heading 2 +> -- + +> not heading 1 +== +> not heading 2 with br +-- diff --git a/test/specs/new/setext_no_blankline.html b/test/specs/new/setext_no_blankline.html index 88657aa7..695eecc7 100644 --- a/test/specs/new/setext_no_blankline.html +++ b/test/specs/new/setext_no_blankline.html @@ -4,8 +4,6 @@

fenced code block

=
 
-

blockquote

-

heading

=

diff --git a/test/specs/new/setext_no_blankline.md b/test/specs/new/setext_no_blankline.md index f98ebd63..33bd2540 100644 --- a/test/specs/new/setext_no_blankline.md +++ b/test/specs/new/setext_no_blankline.md @@ -6,9 +6,6 @@ fenced code block = ``` -> blockquote -= - ### heading =