Fix some html entities (dart-lang/markdown#256)
Fix the HTML-ification of ", <, >
diff --git a/pkgs/markdown/CHANGELOG.md b/pkgs/markdown/CHANGELOG.md
index 049c246..7962de8 100644
--- a/pkgs/markdown/CHANGELOG.md
+++ b/pkgs/markdown/CHANGELOG.md
@@ -5,6 +5,8 @@
* Improve strict spec compliance for `blockquote` by always putting the closing
tag on a new line.
* Improve strict spec compliance for `code` elements defined with "\`".
+* Properly encode `<`, `>`, and `"` as their respective HTML entities when
+ interpreted as text.
## 2.0.3
diff --git a/pkgs/markdown/lib/src/inline_parser.dart b/pkgs/markdown/lib/src/inline_parser.dart
index a1fede5..10b56f2 100644
--- a/pkgs/markdown/lib/src/inline_parser.dart
+++ b/pkgs/markdown/lib/src/inline_parser.dart
@@ -234,8 +234,20 @@
EscapeSyntax() : super(r'''\\[!"#$%&'()*+,\-./:;<=>?@\[\\\]^_`{|}~]''');
bool onMatch(InlineParser parser, Match match) {
- // Insert the substitution.
- parser.addNode(Text(match[0][1]));
+ final char = match[0].codeUnitAt(1);
+ // Insert the substitution. Why these three charactes are replaced with
+ // their equivalent HTML entity referenced appears to be missing from the
+ // CommonMark spec, but is very present in all of the examples.
+ // https://talk.commonmark.org/t/entity-ification-of-quotes-and-brackets-missing-from-spec/3207
+ if (char == $double_quote) {
+ parser.addNode(Text('"'));
+ } else if (char == $lt) {
+ parser.addNode(Text('<'));
+ } else if (char == $gt) {
+ parser.addNode(Text('>'));
+ } else {
+ parser.addNode(Text(match[0][1]));
+ }
return true;
}
}
diff --git a/pkgs/markdown/test/common_mark/backslash_escapes.unit b/pkgs/markdown/test/common_mark/backslash_escapes.unit
index f16ddfd..f906dc3 100644
--- a/pkgs/markdown/test/common_mark/backslash_escapes.unit
+++ b/pkgs/markdown/test/common_mark/backslash_escapes.unit
@@ -1,7 +1,7 @@
>>> Backslash escapes - 298
\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~
<<<
-<p>!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~</p>
+<p>!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~</p>
>>> Backslash escapes - 299
\ \A\a\ \3\φ\«
<<<
@@ -18,7 +18,7 @@
\ö not a character entity
<<<
<p>*not emphasized*
-<br/> not a tag
+<br/> not a tag
[not a link](/foo)
`not code`
1. not a list
diff --git a/pkgs/markdown/test/common_mark/link_reference_definitions.unit b/pkgs/markdown/test/common_mark/link_reference_definitions.unit
index 388ed8d..16f86fb 100644
--- a/pkgs/markdown/test/common_mark/link_reference_definitions.unit
+++ b/pkgs/markdown/test/common_mark/link_reference_definitions.unit
@@ -84,7 +84,7 @@
[foo]
<<<
-<p>[foo]: /url\bar*baz "foo"bar\baz"</p>
+<p>[foo]: /url\bar*baz "foo"bar\baz"</p>
<p>[foo]</p>
>>> Link reference definitions - 172
[foo]
diff --git a/pkgs/markdown/test/common_mark/links.unit b/pkgs/markdown/test/common_mark/links.unit
index 7f9707f..fb9cf5f 100644
--- a/pkgs/markdown/test/common_mark/links.unit
+++ b/pkgs/markdown/test/common_mark/links.unit
@@ -41,7 +41,7 @@
>>> Links - 490
[link](<foo\>)
<<<
-<p>[link](<foo>)</p>
+<p>[link](<foo>)</p>
>>> Links - 491
[a](<b)c
[a](<b)c>
diff --git a/pkgs/markdown/test/common_mark/setext_headings.unit b/pkgs/markdown/test/common_mark/setext_headings.unit
index 563018d..e0e4572 100644
--- a/pkgs/markdown/test/common_mark/setext_headings.unit
+++ b/pkgs/markdown/test/common_mark/setext_headings.unit
@@ -183,7 +183,7 @@
\> foo
------
<<<
-<h2>> foo</h2>
+<h2>> foo</h2>
>>> Setext headings - 73
Foo
diff --git a/pkgs/markdown/test/gfm/backslash_escapes.unit b/pkgs/markdown/test/gfm/backslash_escapes.unit
index ca03f36..e0f5dfb 100644
--- a/pkgs/markdown/test/gfm/backslash_escapes.unit
+++ b/pkgs/markdown/test/gfm/backslash_escapes.unit
@@ -1,7 +1,7 @@
>>> Backslash escapes - 308
\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~
<<<
-<p>!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~</p>
+<p>!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~</p>
>>> Backslash escapes - 309
\ \A\a\ \3\φ\«
<<<
@@ -18,7 +18,7 @@
\ö not a character entity
<<<
<p>*not emphasized*
-<br/> not a tag
+<br/> not a tag
[not a link](/foo)
`not code`
1. not a list
diff --git a/pkgs/markdown/test/gfm/link_reference_definitions.unit b/pkgs/markdown/test/gfm/link_reference_definitions.unit
index 388ed8d..16f86fb 100644
--- a/pkgs/markdown/test/gfm/link_reference_definitions.unit
+++ b/pkgs/markdown/test/gfm/link_reference_definitions.unit
@@ -84,7 +84,7 @@
[foo]
<<<
-<p>[foo]: /url\bar*baz "foo"bar\baz"</p>
+<p>[foo]: /url\bar*baz "foo"bar\baz"</p>
<p>[foo]</p>
>>> Link reference definitions - 172
[foo]
diff --git a/pkgs/markdown/test/gfm/links.unit b/pkgs/markdown/test/gfm/links.unit
index a64166a..698282d 100644
--- a/pkgs/markdown/test/gfm/links.unit
+++ b/pkgs/markdown/test/gfm/links.unit
@@ -41,7 +41,7 @@
>>> Links - 502
[link](<foo\>)
<<<
-<p>[link](<foo>)</p>
+<p>[link](<foo>)</p>
>>> Links - 503
[a](<b)c
[a](<b)c>
diff --git a/pkgs/markdown/test/gfm/setext_headings.unit b/pkgs/markdown/test/gfm/setext_headings.unit
index 563018d..e0e4572 100644
--- a/pkgs/markdown/test/gfm/setext_headings.unit
+++ b/pkgs/markdown/test/gfm/setext_headings.unit
@@ -183,7 +183,7 @@
\> foo
------
<<<
-<h2>> foo</h2>
+<h2>> foo</h2>
>>> Setext headings - 73
Foo
diff --git a/pkgs/markdown/test/original/backslash_escapes.unit b/pkgs/markdown/test/original/backslash_escapes.unit
index 8828c49..05a8c99 100644
--- a/pkgs/markdown/test/original/backslash_escapes.unit
+++ b/pkgs/markdown/test/original/backslash_escapes.unit
@@ -5,8 +5,8 @@
and \~.
<<<
-<p>Punctuations like ! and " and # and $ and % and & and ' and ( and )
-and * and + and , and - and . and / and : and ; and < and = and >
+<p>Punctuations like ! and " and # and $ and % and & and ' and ( and )
+and * and + and , and - and . and / and : and ; and < and = and >
and ? and @ and [ and \ and ] and ^ and _ and ` and { and | and }
and ~.</p>
>>> Inline code blocks can be escaped.
diff --git a/pkgs/markdown/tool/common_mark_stats.json b/pkgs/markdown/tool/common_mark_stats.json
index 5318f46..a250f90 100644
--- a/pkgs/markdown/tool/common_mark_stats.json
+++ b/pkgs/markdown/tool/common_mark_stats.json
@@ -43,7 +43,7 @@
"Backslash escapes": {
"298": "loose",
"299": "strict",
- "300": "fail",
+ "300": "loose",
"301": "strict",
"302": "strict",
"303": "strict",
@@ -435,7 +435,7 @@
"487": "strict",
"488": "strict",
"489": "strict",
- "490": "loose",
+ "490": "strict",
"491": "strict",
"492": "strict",
"493": "strict",
@@ -651,7 +651,7 @@
"69": "strict",
"70": "strict",
"71": "strict",
- "72": "loose",
+ "72": "strict",
"73": "strict",
"74": "strict",
"75": "strict",
diff --git a/pkgs/markdown/tool/common_mark_stats.txt b/pkgs/markdown/tool/common_mark_stats.txt
index 86ccf5d..249ed10 100644
--- a/pkgs/markdown/tool/common_mark_stats.txt
+++ b/pkgs/markdown/tool/common_mark_stats.txt
@@ -1,6 +1,6 @@
17 of 18 – 94.4% ATX headings
19 of 19 – 100.0% Autolinks
- 11 of 13 – 84.6% Backslash escapes
+ 12 of 13 – 92.3% Backslash escapes
1 of 1 – 100.0% Blank lines
22 of 25 – 88.0% Block quotes
21 of 22 – 95.5% Code spans
@@ -24,5 +24,5 @@
11 of 11 – 100.0% Tabs
3 of 3 – 100.0% Textual content
19 of 19 – 100.0% Thematic breaks
- 597 of 649 – 92.0% TOTAL
- 523 of 597 – 87.6% TOTAL Strict
+ 598 of 649 – 92.1% TOTAL
+ 525 of 598 – 87.8% TOTAL Strict
diff --git a/pkgs/markdown/tool/gfm_stats.json b/pkgs/markdown/tool/gfm_stats.json
index a1ac55f..243cd6c 100644
--- a/pkgs/markdown/tool/gfm_stats.json
+++ b/pkgs/markdown/tool/gfm_stats.json
@@ -56,7 +56,7 @@
"Backslash escapes": {
"308": "loose",
"309": "strict",
- "310": "fail",
+ "310": "loose",
"311": "strict",
"312": "strict",
"313": "strict",
@@ -451,7 +451,7 @@
"499": "strict",
"500": "strict",
"501": "strict",
- "502": "loose",
+ "502": "strict",
"503": "strict",
"504": "strict",
"505": "strict",
@@ -667,7 +667,7 @@
"69": "strict",
"70": "strict",
"71": "strict",
- "72": "loose",
+ "72": "strict",
"73": "strict",
"74": "strict",
"75": "strict",
diff --git a/pkgs/markdown/tool/gfm_stats.txt b/pkgs/markdown/tool/gfm_stats.txt
index 3c7f6ba..ab2fb17 100644
--- a/pkgs/markdown/tool/gfm_stats.txt
+++ b/pkgs/markdown/tool/gfm_stats.txt
@@ -1,7 +1,7 @@
17 of 18 – 94.4% ATX headings
17 of 19 – 89.5% Autolinks
8 of 11 – 72.7% Autolinks (extension)
- 11 of 13 – 84.6% Backslash escapes
+ 12 of 13 – 92.3% Backslash escapes
1 of 1 – 100.0% Blank lines
22 of 25 – 88.0% Block quotes
21 of 22 – 95.5% Code spans
@@ -28,5 +28,5 @@
11 of 11 – 100.0% Tabs
3 of 3 – 100.0% Textual content
19 of 19 – 100.0% Thematic breaks
- 612 of 671 – 91.2% TOTAL
- 529 of 612 – 86.4% TOTAL Strict
+ 613 of 671 – 91.4% TOTAL
+ 531 of 613 – 86.6% TOTAL Strict