Add line endings before HTML blocks (dart-lang/markdown#508)
diff --git a/pkgs/markdown/CHANGELOG.md b/pkgs/markdown/CHANGELOG.md index 469bf8b..4deb4ea 100644 --- a/pkgs/markdown/CHANGELOG.md +++ b/pkgs/markdown/CHANGELOG.md
@@ -25,6 +25,7 @@ `BlockParser`, which can be used when parsing nested blocks. * Add a new optional parameter `disabledSetextHeading` for `parseLines()` of `BlockParser`, which is used to disable the `SetextHeaderSyntax`. +* Add a new public property `previousSyntax` for `BlockParser`. ## 6.0.1
diff --git a/pkgs/markdown/lib/src/block_parser.dart b/pkgs/markdown/lib/src/block_parser.dart index 675d8c7..fc0c1ac 100644 --- a/pkgs/markdown/lib/src/block_parser.dart +++ b/pkgs/markdown/lib/src/block_parser.dart
@@ -144,6 +144,10 @@ BlockSyntax? get currentSyntax => _currentSyntax; BlockSyntax? _currentSyntax; + /// The [BlockSyntax] which is running before the [currentSyntax]. + BlockSyntax? get previousSyntax => _previousSyntax; + BlockSyntax? _previousSyntax; + List<Node> parseLines({ BlockSyntax? parentSyntax, bool disabledSetextHeading = false, @@ -167,6 +171,7 @@ } if (syntax.canParse(this)) { + _previousSyntax = _currentSyntax; _currentSyntax = syntax; final positionBefore = _pos; final block = syntax.parse(this);
diff --git a/pkgs/markdown/lib/src/block_syntaxes/html_block_syntax.dart b/pkgs/markdown/lib/src/block_syntaxes/html_block_syntax.dart index 642481f..a69cc3f 100644 --- a/pkgs/markdown/lib/src/block_syntaxes/html_block_syntax.dart +++ b/pkgs/markdown/lib/src/block_syntaxes/html_block_syntax.dart
@@ -87,6 +87,12 @@ @override Node parse(BlockParser parser) { final childLines = parseChildLines(parser); - return Text(childLines.map((e) => e.content).join('\n').trimRight()); + + var text = childLines.map((e) => e.content).join('\n').trimRight(); + if (parser.previousSyntax != null) { + text = '\n$text'; + } + + return Text(text); } }
diff --git a/pkgs/markdown/test/common_mark/html_blocks.unit b/pkgs/markdown/test/common_mark/html_blocks.unit index 54b229c..9986356 100644 --- a/pkgs/markdown/test/common_mark/html_blocks.unit +++ b/pkgs/markdown/test/common_mark/html_blocks.unit
@@ -11,7 +11,8 @@ <pre> **Hello**, <p><em>world</em>. -</pre></p></td></tr></table> +</pre></p> +</td></tr></table> >>> HTML blocks - 149 <table> <tr> @@ -53,7 +54,8 @@ </DIV> <<< <DIV CLASS="foo"> -<p><em>Markdown</em></p></DIV> +<p><em>Markdown</em></p> +</DIV> >>> HTML blocks - 153 <div id="foo" class="bar"> @@ -165,7 +167,8 @@ </del> <<< <del> -<p><em>foo</em></p></del> +<p><em>foo</em></p> +</del> >>> HTML blocks - 168 <del>*foo*</del> <<< @@ -360,7 +363,8 @@ bar </div> <<< -<p>Foo</p><div> +<p>Foo</p> +<div> bar </div> >>> HTML blocks - 186 @@ -389,7 +393,8 @@ </div> <<< <div> -<p><em>Emphasized</em> text.</p></div> +<p><em>Emphasized</em> text.</p> +</div> >>> HTML blocks - 189 <div> *Emphasized* text. @@ -436,5 +441,6 @@ <pre><code><td> Hi </td> -</code></pre> </tr> +</code></pre> + </tr> </table>
diff --git a/pkgs/markdown/test/common_mark/lists.unit b/pkgs/markdown/test/common_mark/lists.unit index e0422fd..fce59fe 100644 --- a/pkgs/markdown/test/common_mark/lists.unit +++ b/pkgs/markdown/test/common_mark/lists.unit
@@ -99,7 +99,8 @@ <ul> <li>foo</li> <li>bar</li> -</ul><!-- --> +</ul> +<!-- --> <ul> <li>baz</li> <li>bim</li> @@ -123,7 +124,8 @@ <li> <p>foo</p> </li> -</ul><!-- --> +</ul> +<!-- --> <pre><code>code </code></pre> >>> Lists - 310
diff --git a/pkgs/markdown/test/document_test.dart b/pkgs/markdown/test/document_test.dart index adfa009..3e30697 100644 --- a/pkgs/markdown/test/document_test.dart +++ b/pkgs/markdown/test/document_test.dart
@@ -57,7 +57,7 @@ final document = Document(); final nodes = BlockParser(contents.toLines(), document).parseLines(); final result = HtmlRenderer().render(nodes); - expect(result, '<p>\n</p><pre>\n A\n B\n</pre>'); + expect(result, '<p>\n</p>\n<pre>\n A\n B\n</pre>'); }); test('encode double quotes, greater than, and less than when escaped',
diff --git a/pkgs/markdown/test/gfm/disallowed_raw_html_extension.unit b/pkgs/markdown/test/gfm/disallowed_raw_html_extension.unit index ad8c3e2..34cc396 100644 --- a/pkgs/markdown/test/gfm/disallowed_raw_html_extension.unit +++ b/pkgs/markdown/test/gfm/disallowed_raw_html_extension.unit
@@ -5,6 +5,7 @@ <xmp> is disallowed. <XMP> is also disallowed. </blockquote> <<< -<p><strong> <title> <style> <em></p><blockquote> +<p><strong> <title> <style> <em></p> +<blockquote> <xmp> is disallowed. <XMP> is also disallowed. </blockquote>
diff --git a/pkgs/markdown/test/gfm/html_blocks.unit b/pkgs/markdown/test/gfm/html_blocks.unit index f2562f4..0799464 100644 --- a/pkgs/markdown/test/gfm/html_blocks.unit +++ b/pkgs/markdown/test/gfm/html_blocks.unit
@@ -11,7 +11,8 @@ <pre> **Hello**, <p><em>world</em>. -</pre></p></td></tr></table> +</pre></p> +</td></tr></table> >>> HTML blocks - 119 <table> <tr> @@ -53,7 +54,8 @@ </DIV> <<< <DIV CLASS="foo"> -<p><em>Markdown</em></p></DIV> +<p><em>Markdown</em></p> +</DIV> >>> HTML blocks - 123 <div id="foo" class="bar"> @@ -165,7 +167,8 @@ </del> <<< <del> -<p><em>foo</em></p></del> +<p><em>foo</em></p> +</del> >>> HTML blocks - 138 <del>*foo*</del> <<< @@ -344,7 +347,8 @@ bar </div> <<< -<p>Foo</p><div> +<p>Foo</p> +<div> bar </div> >>> HTML blocks - 155 @@ -373,7 +377,8 @@ </div> <<< <div> -<p><em>Emphasized</em> text.</p></div> +<p><em>Emphasized</em> text.</p> +</div> >>> HTML blocks - 158 <div> *Emphasized* text. @@ -420,5 +425,6 @@ <pre><code><td> Hi </td> -</code></pre> </tr> +</code></pre> + </tr> </table>
diff --git a/pkgs/markdown/test/gfm/lists.unit b/pkgs/markdown/test/gfm/lists.unit index bc675e5..e5802db 100644 --- a/pkgs/markdown/test/gfm/lists.unit +++ b/pkgs/markdown/test/gfm/lists.unit
@@ -99,7 +99,8 @@ <ul> <li>foo</li> <li>bar</li> -</ul><!-- --> +</ul> +<!-- --> <ul> <li>baz</li> <li>bim</li> @@ -123,7 +124,8 @@ <li> <p>foo</p> </li> -</ul><!-- --> +</ul> +<!-- --> <pre><code>code </code></pre> >>> Lists - 290
diff --git a/pkgs/markdown/tool/common_mark_stats.json b/pkgs/markdown/tool/common_mark_stats.json index b3d17a9..aee10cd 100644 --- a/pkgs/markdown/tool/common_mark_stats.json +++ b/pkgs/markdown/tool/common_mark_stats.json
@@ -310,11 +310,11 @@ "647": "strict" }, "HTML blocks": { - "148": "loose", + "148": "strict", "149": "strict", "150": "strict", "151": "strict", - "152": "loose", + "152": "strict", "153": "strict", "154": "strict", "155": "strict", @@ -329,7 +329,7 @@ "164": "strict", "165": "strict", "166": "strict", - "167": "loose", + "167": "strict", "168": "strict", "169": "strict", "170": "strict", @@ -347,13 +347,13 @@ "182": "strict", "183": "strict", "184": "strict", - "185": "loose", + "185": "strict", "186": "strict", "187": "strict", - "188": "loose", + "188": "strict", "189": "strict", "190": "strict", - "191": "loose" + "191": "strict" }, "Images": { "571": "strict", @@ -575,8 +575,8 @@ "305": "strict", "306": "strict", "307": "strict", - "308": "loose", - "309": "loose", + "308": "strict", + "309": "strict", "310": "strict", "311": "strict", "312": "strict",
diff --git a/pkgs/markdown/tool/common_mark_stats.txt b/pkgs/markdown/tool/common_mark_stats.txt index faf5757..9fcddd0 100644 --- a/pkgs/markdown/tool/common_mark_stats.txt +++ b/pkgs/markdown/tool/common_mark_stats.txt
@@ -25,4 +25,4 @@ 3 of 3 – 100.0% Textual content 19 of 19 – 100.0% Thematic breaks 652 of 652 – 100.0% TOTAL - 635 of 652 – 97.4% TOTAL Strict + 643 of 652 – 98.6% TOTAL Strict
diff --git a/pkgs/markdown/tool/gfm_stats.json b/pkgs/markdown/tool/gfm_stats.json index 7b5f993..1bb291a 100644 --- a/pkgs/markdown/tool/gfm_stats.json +++ b/pkgs/markdown/tool/gfm_stats.json
@@ -123,7 +123,7 @@ "359": "strict" }, "Disallowed Raw HTML (extension)": { - "652": "fail" + "652": "loose" }, "Emphasis and strong emphasis": { "360": "strict", @@ -326,11 +326,11 @@ "667": "strict" }, "HTML blocks": { - "118": "loose", + "118": "strict", "119": "strict", "120": "strict", "121": "strict", - "122": "loose", + "122": "strict", "123": "strict", "124": "strict", "125": "strict", @@ -345,7 +345,7 @@ "134": "strict", "135": "strict", "136": "strict", - "137": "loose", + "137": "strict", "138": "strict", "139": "strict", "140": "strict", @@ -362,13 +362,13 @@ "151": "strict", "152": "strict", "153": "strict", - "154": "loose", + "154": "strict", "155": "strict", "156": "strict", - "157": "loose", + "157": "strict", "158": "strict", "159": "strict", - "160": "loose" + "160": "strict" }, "Images": { "580": "strict", @@ -588,8 +588,8 @@ "285": "strict", "286": "strict", "287": "strict", - "288": "loose", - "289": "loose", + "288": "strict", + "289": "strict", "290": "strict", "291": "strict", "292": "strict",
diff --git a/pkgs/markdown/tool/gfm_stats.txt b/pkgs/markdown/tool/gfm_stats.txt index 03a5fe1..f6b4a81 100644 --- a/pkgs/markdown/tool/gfm_stats.txt +++ b/pkgs/markdown/tool/gfm_stats.txt
@@ -5,7 +5,7 @@ 1 of 1 – 100.0% Blank lines 25 of 25 – 100.0% Block quotes 22 of 22 – 100.0% Code spans - 0 of 1 – 0.0% Disallowed Raw HTML (extension) + 1 of 1 – 100.0% Disallowed Raw HTML (extension) 131 of 131 – 100.0% Emphasis and strong emphasis 17 of 17 – 100.0% Entity and numeric character references 29 of 29 – 100.0% Fenced code blocks @@ -28,5 +28,5 @@ 11 of 11 – 100.0% Tabs 3 of 3 – 100.0% Textual content 19 of 19 – 100.0% Thematic breaks - 669 of 670 – 99.9% TOTAL - 649 of 669 – 97.0% TOTAL Strict + 670 of 670 – 100.0% TOTAL + 657 of 670 – 98.1% TOTAL Strict