From 15f3f157de6ec4bce90707b848c7026034388a39 Mon Sep 17 00:00:00 2001 From: Kiyoka Nishiyama Date: Mon, 13 Jun 2022 12:15:06 +0900 Subject: [PATCH] fix: Code and heading after list without blank line (#2483) --- src/Tokenizer.js | 11 +++++++++ test/specs/new/fences_following_list.html | 7 ++++++ test/specs/new/fences_following_list.md | 5 ++++ ...ences_with_blankline_following_list_0.html | 23 +++++++++++++++++++ .../fences_with_blankline_following_list_0.md | 22 ++++++++++++++++++ ...ences_with_blankline_following_list_1.html | 22 ++++++++++++++++++ .../fences_with_blankline_following_list_1.md | 23 +++++++++++++++++++ test/specs/new/heading_following_list.html | 8 +++++++ test/specs/new/heading_following_list.md | 6 +++++ 9 files changed, 127 insertions(+) create mode 100644 test/specs/new/fences_following_list.html create mode 100644 test/specs/new/fences_following_list.md create mode 100644 test/specs/new/fences_with_blankline_following_list_0.html create mode 100644 test/specs/new/fences_with_blankline_following_list_0.md create mode 100644 test/specs/new/fences_with_blankline_following_list_1.html create mode 100644 test/specs/new/fences_with_blankline_following_list_1.md create mode 100644 test/specs/new/heading_following_list.html create mode 100644 test/specs/new/heading_following_list.md diff --git a/src/Tokenizer.js b/src/Tokenizer.js index e8a69b6759..0f77a01050 100644 --- a/src/Tokenizer.js +++ b/src/Tokenizer.js @@ -226,6 +226,7 @@ export class Tokenizer { if (!endEarly) { const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?: [^\\n]*)?(?:\\n|$))`); const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`); + const fencesBeginRegex = new RegExp(`^( {0,${Math.min(3, indent - 1)}})(\`\`\`|~~~)`); // Check if following lines should be included in List Item while (src) { @@ -237,6 +238,16 @@ export class Tokenizer { line = line.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' '); } + // End list item if found code fences + if (fencesBeginRegex.test(line)) { + break; + } + + // End list item if found start of new heading + if (this.rules.block.heading.test(line)) { + break; + } + // End list item if found start of new bullet if (nextBulletRegex.test(line)) { break; diff --git a/test/specs/new/fences_following_list.html b/test/specs/new/fences_following_list.html new file mode 100644 index 0000000000..e5b2a9f9e7 --- /dev/null +++ b/test/specs/new/fences_following_list.html @@ -0,0 +1,7 @@ +
    +
  1. abcd
  2. +
+
if {
+
+}
+
diff --git a/test/specs/new/fences_following_list.md b/test/specs/new/fences_following_list.md new file mode 100644 index 0000000000..f306891f9c --- /dev/null +++ b/test/specs/new/fences_following_list.md @@ -0,0 +1,5 @@ +1. abcd +``` +if { +} +``` diff --git a/test/specs/new/fences_with_blankline_following_list_0.html b/test/specs/new/fences_with_blankline_following_list_0.html new file mode 100644 index 0000000000..cc77e8b936 --- /dev/null +++ b/test/specs/new/fences_with_blankline_following_list_0.html @@ -0,0 +1,23 @@ +
    +
  1. code with blankline
  2. +
+
if {
+
+}
+
+
    +
  1. code and text
  2. +
+
if {
+
+}
+
+

text after fenced code block.

+
    +
  1. tilde
  2. +
+
if {
+
+
+}
+
diff --git a/test/specs/new/fences_with_blankline_following_list_0.md b/test/specs/new/fences_with_blankline_following_list_0.md new file mode 100644 index 0000000000..2ea9a26285 --- /dev/null +++ b/test/specs/new/fences_with_blankline_following_list_0.md @@ -0,0 +1,22 @@ +1. code with blankline +``` +if { + +} +``` + +2. code and text +``` +if { + + +} +``` +text after fenced code block. + +3. tilde +~~~ +if { + +} +~~~ diff --git a/test/specs/new/fences_with_blankline_following_list_1.html b/test/specs/new/fences_with_blankline_following_list_1.html new file mode 100644 index 0000000000..31e59331ef --- /dev/null +++ b/test/specs/new/fences_with_blankline_following_list_1.html @@ -0,0 +1,22 @@ +
    +
  1. code with blankline

    +
    if {
    +
    +}
    +
    +
  2. +
  3. code and text

    +
    if {
    +
    +}
    +
    +

    text after fenced code block.

    +
  4. +
  5. tilde

    +
    if {
    +
    +
    +}
    +
    +
  6. +
diff --git a/test/specs/new/fences_with_blankline_following_list_1.md b/test/specs/new/fences_with_blankline_following_list_1.md new file mode 100644 index 0000000000..5f356a8aa8 --- /dev/null +++ b/test/specs/new/fences_with_blankline_following_list_1.md @@ -0,0 +1,23 @@ +1. code with blankline + ``` + if { + + } + ``` + +2. code and text + ``` + if { + + + } + ``` + text after fenced code block. + +3. tilde + ~~~ + if { + + } + ~~~ + diff --git a/test/specs/new/heading_following_list.html b/test/specs/new/heading_following_list.html new file mode 100644 index 0000000000..b022d175ea --- /dev/null +++ b/test/specs/new/heading_following_list.html @@ -0,0 +1,8 @@ +

level1

+

level2

+

level3

+ +

level3

diff --git a/test/specs/new/heading_following_list.md b/test/specs/new/heading_following_list.md new file mode 100644 index 0000000000..215e308800 --- /dev/null +++ b/test/specs/new/heading_following_list.md @@ -0,0 +1,6 @@ +# level1 +## level2 +### level3 +- foo=bar +- foo2=bar2 +### level3