An empty list cannot interrupt a paragraph. (#317)
An empty list cannot interrupt a paragraph.
diff --git a/lib/src/block_parser.dart b/lib/src/block_parser.dart
index f898e88..0cf4454 100644
--- a/lib/src/block_parser.dart
+++ b/lib/src/block_parser.dart
@@ -193,7 +193,21 @@
/// Gets whether or not [parser]'s current line should end the previous block.
static bool isAtBlockEnd(BlockParser parser) {
if (parser.isDone) return true;
- return parser.blockSyntaxes.any((s) => s.canParse(parser) && s.canEndBlock);
+ return parser.blockSyntaxes.any((s) {
+ if (!s.canParse(parser)) return false;
+ if (s is ListSyntax) {
+ // An empty list cannot interrupt a paragraph. See
+ // https://spec.commonmark.org/0.29/#example-255.
+ // Ideally, [BlockSyntax.canEndBlock] should be changed to be a method
+ // which accepts a [BlockParser], but this would be a breaking change,
+ // so we're going with this temporarily.
+ var match = s.pattern.firstMatch(parser.current);
+ // The seventh group, in both [_olPattern] and [_ulPattern] is the text
+ // after the delimiter.
+ return match[7]?.isNotEmpty ?? false;
+ }
+ return s.canEndBlock;
+ });
}
/// Generates a valid HTML anchor from the inner text of [element].
diff --git a/test/common_mark/emphasis_and_strong_emphasis.unit b/test/common_mark/emphasis_and_strong_emphasis.unit
index f93b96d..5b4b11f 100644
--- a/test/common_mark/emphasis_and_strong_emphasis.unit
+++ b/test/common_mark/emphasis_and_strong_emphasis.unit
@@ -66,10 +66,8 @@
*foo bar
*
<<<
-<p>*foo bar</p>
-<ul>
-<li></li>
-</ul>
+<p>*foo bar
+*</p>
>>> Emphasis and strong emphasis - 367
*(*foo)
<<<
diff --git a/test/common_mark/list_items.unit b/test/common_mark/list_items.unit
index 87a7cec..9b83443 100644
--- a/test/common_mark/list_items.unit
+++ b/test/common_mark/list_items.unit
@@ -359,14 +359,10 @@
foo
1.
<<<
-<p>foo</p>
-<ul>
-<li></li>
-</ul>
-<p>foo</p>
-<ol>
-<li></li>
-</ol>
+<p>foo
+*</p>
+<p>foo
+1.</p>
>>> List items - 256
1. A paragraph
with two lines.
diff --git a/test/gfm/emphasis_and_strong_emphasis.unit b/test/gfm/emphasis_and_strong_emphasis.unit
index 33f407b..a42c149 100644
--- a/test/gfm/emphasis_and_strong_emphasis.unit
+++ b/test/gfm/emphasis_and_strong_emphasis.unit
@@ -66,10 +66,8 @@
*foo bar
*
<<<
-<p>*foo bar</p>
-<ul>
-<li></li>
-</ul>
+<p>*foo bar
+*</p>
>>> Emphasis and strong emphasis - 377
*(*foo)
<<<
diff --git a/test/gfm/list_items.unit b/test/gfm/list_items.unit
index 90ff27f..fae2958 100644
--- a/test/gfm/list_items.unit
+++ b/test/gfm/list_items.unit
@@ -359,14 +359,10 @@
foo
1.
<<<
-<p>foo</p>
-<ul>
-<li></li>
-</ul>
-<p>foo</p>
-<ol>
-<li></li>
-</ol>
+<p>foo
+*</p>
+<p>foo
+1.</p>
>>> List items - 264
1. A paragraph
with two lines.
diff --git a/tool/common_mark_stats.json b/tool/common_mark_stats.json
index 26f32eb..bb4f384 100644
--- a/tool/common_mark_stats.json
+++ b/tool/common_mark_stats.json
@@ -126,7 +126,7 @@
"363": "strict",
"364": "strict",
"365": "strict",
- "366": "fail",
+ "366": "strict",
"367": "strict",
"368": "strict",
"369": "strict",
@@ -547,7 +547,7 @@
"252": "strict",
"253": "strict",
"254": "strict",
- "255": "fail",
+ "255": "strict",
"256": "strict",
"257": "strict",
"258": "strict",
diff --git a/tool/common_mark_stats.txt b/tool/common_mark_stats.txt
index 4bbd5af..dc133e7 100644
--- a/tool/common_mark_stats.txt
+++ b/tool/common_mark_stats.txt
@@ -4,7 +4,7 @@
1 of 1 – 100.0% Blank lines
22 of 25 – 88.0% Block quotes
22 of 22 – 100.0% Code spans
- 125 of 131 – 95.4% Emphasis and strong emphasis
+ 126 of 131 – 96.2% Emphasis and strong emphasis
14 of 17 – 82.4% Entity and numeric character references
28 of 29 – 96.6% Fenced code blocks
15 of 15 – 100.0% Hard line breaks
@@ -14,7 +14,7 @@
1 of 1 – 100.0% Inlines
21 of 28 – 75.0% Link reference definitions
78 of 87 – 89.7% Links
- 44 of 48 – 91.7% List items
+ 45 of 48 – 93.8% List items
22 of 26 – 84.6% Lists
8 of 8 – 100.0% Paragraphs
1 of 1 – 100.0% Precedence
@@ -24,5 +24,5 @@
11 of 11 – 100.0% Tabs
3 of 3 – 100.0% Textual content
19 of 19 – 100.0% Thematic breaks
- 601 of 649 – 92.6% TOTAL
- 527 of 601 – 87.7% TOTAL Strict
+ 603 of 649 – 92.9% TOTAL
+ 529 of 603 – 87.7% TOTAL Strict
diff --git a/tool/gfm_stats.json b/tool/gfm_stats.json
index 0abf0c3..47b76a2 100644
--- a/tool/gfm_stats.json
+++ b/tool/gfm_stats.json
@@ -142,7 +142,7 @@
"373": "strict",
"374": "strict",
"375": "strict",
- "376": "fail",
+ "376": "strict",
"377": "strict",
"378": "strict",
"379": "strict",
@@ -563,7 +563,7 @@
"260": "strict",
"261": "strict",
"262": "strict",
- "263": "fail",
+ "263": "strict",
"264": "strict",
"265": "strict",
"266": "strict",
diff --git a/tool/gfm_stats.txt b/tool/gfm_stats.txt
index d471838..9c60214 100644
--- a/tool/gfm_stats.txt
+++ b/tool/gfm_stats.txt
@@ -6,7 +6,7 @@
22 of 25 – 88.0% Block quotes
22 of 22 – 100.0% Code spans
0 of 1 – 0.0% Disallowed Raw HTML (extension)
- 125 of 131 – 95.4% Emphasis and strong emphasis
+ 126 of 131 – 96.2% Emphasis and strong emphasis
14 of 17 – 82.4% Entity and numeric character references
28 of 29 – 96.6% Fenced code blocks
15 of 15 – 100.0% Hard line breaks
@@ -16,7 +16,7 @@
1 of 1 – 100.0% Inlines
21 of 28 – 75.0% Link reference definitions
78 of 87 – 89.7% Links
- 44 of 48 – 91.7% List items
+ 45 of 48 – 93.8% List items
22 of 26 – 84.6% Lists
8 of 8 – 100.0% Paragraphs
1 of 1 – 100.0% Precedence
@@ -28,5 +28,5 @@
11 of 11 – 100.0% Tabs
3 of 3 – 100.0% Textual content
19 of 19 – 100.0% Thematic breaks
- 616 of 671 – 91.8% TOTAL
- 533 of 616 – 86.5% TOTAL Strict
+ 618 of 671 – 92.1% TOTAL
+ 535 of 618 – 86.6% TOTAL Strict