Allow space in a pointy-bracked inline link (#349)
diff --git a/lib/src/inline_parser.dart b/lib/src/inline_parser.dart
index ccdb3d2..46db2e6 100644
--- a/lib/src/inline_parser.dart
+++ b/lib/src/inline_parser.dart
@@ -93,7 +93,7 @@
syntaxes.addAll(_defaultSyntaxes);
- if (document.encodeHtml) {
+ if (_encodeHtml) {
syntaxes.addAll(_htmlSyntaxes);
}
}
@@ -337,6 +337,8 @@
pos += length;
start = pos;
}
+
+ bool get _encodeHtml => document.encodeHtml;
}
/// Represents one kind of Markdown tag that can be parsed.
@@ -486,7 +488,7 @@
@override
bool onMatch(InlineParser parser, Match match) {
var url = match[1]!;
- var text = parser.document.encodeHtml ? escapeHtml(url) : url;
+ var text = parser._encodeHtml ? escapeHtml(url) : url;
var anchor = Element.text('a', text);
anchor.attributes['href'] = Uri.encodeFull('mailto:$url');
parser.addNode(anchor);
@@ -502,7 +504,7 @@
@override
bool onMatch(InlineParser parser, Match match) {
var url = match[1]!;
- var text = parser.document.encodeHtml ? escapeHtml(url) : url;
+ var text = parser._encodeHtml ? escapeHtml(url) : url;
var anchor = Element.text('a', text);
anchor.attributes['href'] = Uri.encodeFull(url);
parser.addNode(anchor);
@@ -619,7 +621,7 @@
href = 'http://$href';
}
- final text = parser.document.encodeHtml ? escapeHtml(url) : url;
+ final text = parser._encodeHtml ? escapeHtml(url) : url;
final anchor = Element.text('a', text);
anchor.attributes['href'] = Uri.encodeFull(href);
parser.addNode(anchor);
@@ -1170,19 +1172,17 @@
if (char == $backslash) {
parser.advanceBy(1);
var next = parser.charAt(parser.pos);
- if (char == $space || char == $lf || char == $cr || char == $ff) {
- // Not a link (no whitespace allowed within `<...>`).
- return null;
- }
// TODO: Follow the backslash spec better here.
- // http://spec.commonmark.org/0.28/#backslash-escapes
+ // http://spec.commonmark.org/0.29/#backslash-escapes
if (next != $backslash && next != $gt) {
buffer.writeCharCode(char);
}
buffer.writeCharCode(next);
- } else if (char == $space || char == $lf || char == $cr || char == $ff) {
- // Not a link (no whitespace allowed within `<...>`).
+ } else if (char == $lf || char == $cr || char == $ff) {
+ // Not a link (no line breaks allowed within `<...>`).
return null;
+ } else if (char == $space) {
+ buffer.write('%20');
} else if (char == $gt) {
break;
} else {
@@ -1419,7 +1419,7 @@
@override
bool onMatch(InlineParser parser, Match match) {
var code = match[2]!.trim().replaceAll('\n', ' ');
- if (parser.document.encodeHtml) code = escapeHtml(code);
+ if (parser._encodeHtml) code = escapeHtml(code);
parser.addNode(Element.text('code', code));
return true;
diff --git a/test/common_mark/links.unit b/test/common_mark/links.unit
index e362ba8..2274ba7 100644
--- a/test/common_mark/links.unit
+++ b/test/common_mark/links.unit
@@ -21,7 +21,7 @@
>>> Links - 486
[link](</my uri>)
<<<
-<p>[link](</my uri>)</p>
+<p><a href="/my%20uri">link</a></p>
>>> Links - 487
[link](foo
bar)
diff --git a/test/gfm/links.unit b/test/gfm/links.unit
index 9b56101..35266a9 100644
--- a/test/gfm/links.unit
+++ b/test/gfm/links.unit
@@ -21,7 +21,7 @@
>>> Links - 498
[link](</my uri>)
<<<
-<p>[link](</my uri>)</p>
+<p><a href="/my%20uri">link</a></p>
>>> Links - 499
[link](foo
bar)
diff --git a/tool/common_mark_stats.json b/tool/common_mark_stats.json
index 46f7044..901460b 100644
--- a/tool/common_mark_stats.json
+++ b/tool/common_mark_stats.json
@@ -431,7 +431,7 @@
"483": "strict",
"484": "strict",
"485": "strict",
- "486": "fail",
+ "486": "strict",
"487": "strict",
"488": "strict",
"489": "strict",
diff --git a/tool/common_mark_stats.txt b/tool/common_mark_stats.txt
index 2a5cc91..495ba67 100644
--- a/tool/common_mark_stats.txt
+++ b/tool/common_mark_stats.txt
@@ -13,7 +13,7 @@
11 of 12 – 91.7% Indented code blocks
1 of 1 – 100.0% Inlines
21 of 28 – 75.0% Link reference definitions
- 81 of 87 – 93.1% Links
+ 82 of 87 – 94.3% Links
45 of 48 – 93.8% List items
22 of 26 – 84.6% Lists
8 of 8 – 100.0% Paragraphs
@@ -24,5 +24,5 @@
11 of 11 – 100.0% Tabs
3 of 3 – 100.0% Textual content
19 of 19 – 100.0% Thematic breaks
- 610 of 649 – 94.0% TOTAL
- 543 of 610 – 89.0% TOTAL Strict
+ 611 of 649 – 94.1% TOTAL
+ 544 of 611 – 89.0% TOTAL Strict
diff --git a/tool/gfm_stats.json b/tool/gfm_stats.json
index 91699ff..1619615 100644
--- a/tool/gfm_stats.json
+++ b/tool/gfm_stats.json
@@ -447,7 +447,7 @@
"495": "strict",
"496": "strict",
"497": "strict",
- "498": "fail",
+ "498": "strict",
"499": "strict",
"500": "strict",
"501": "strict",
diff --git a/tool/gfm_stats.txt b/tool/gfm_stats.txt
index c1e1819..59a193c 100644
--- a/tool/gfm_stats.txt
+++ b/tool/gfm_stats.txt
@@ -15,7 +15,7 @@
11 of 12 – 91.7% Indented code blocks
1 of 1 – 100.0% Inlines
21 of 28 – 75.0% Link reference definitions
- 81 of 87 – 93.1% Links
+ 82 of 87 – 94.3% Links
45 of 48 – 93.8% List items
22 of 26 – 84.6% Lists
8 of 8 – 100.0% Paragraphs
@@ -28,5 +28,5 @@
11 of 11 – 100.0% Tabs
3 of 3 – 100.0% Textual content
19 of 19 – 100.0% Thematic breaks
- 625 of 671 – 93.1% TOTAL
- 549 of 625 – 87.8% TOTAL Strict
+ 626 of 671 – 93.3% TOTAL
+ 550 of 626 – 87.9% TOTAL Strict