Add support for Email autolinks
diff --git a/pkgs/markdown/CHANGELOG.md b/pkgs/markdown/CHANGELOG.md index b9d162d..0416f37 100644 --- a/pkgs/markdown/CHANGELOG.md +++ b/pkgs/markdown/CHANGELOG.md
@@ -1,6 +1,7 @@ ## 1.0.0 * Remove deprecated `escapeHtml` function. +* Fix compliance with auto-links, including support for email addresses. ## 0.11.4
diff --git a/pkgs/markdown/lib/src/inline_parser.dart b/pkgs/markdown/lib/src/inline_parser.dart index 99a9056..fe99191 100644 --- a/pkgs/markdown/lib/src/inline_parser.dart +++ b/pkgs/markdown/lib/src/inline_parser.dart
@@ -11,6 +11,7 @@ class InlineParser { static final List<InlineSyntax> _defaultSyntaxes = new List<InlineSyntax>.unmodifiable(<InlineSyntax>[ + new EmailAutolinkSyntax(), new AutolinkSyntax(), new LineBreakSyntax(), new LinkSyntax(), @@ -242,6 +243,26 @@ InlineHtmlSyntax() : super(r'<[/!?]?[A-Za-z][A-Za-z0-9-]*(?: [^>]*)?>'); } +/// Matches autolinks like `<foo@bar.example.com>`. +/// +/// See <http://spec.commonmark.org/0.28/#email-address>. +class EmailAutolinkSyntax extends InlineSyntax { + static final _email = + r'''[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}''' + r'''[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*'''; + + EmailAutolinkSyntax() : super('<($_email)>'); + + bool onMatch(InlineParser parser, Match match) { + var url = match[1]; + var anchor = new Element.text('a', escapeHtml(url)); + anchor.attributes['href'] = Uri.encodeFull('mailto:$url'); + parser.addNode(anchor); + + return true; + } +} + /// Matches autolinks like `<http://foo.com>`. class AutolinkSyntax extends InlineSyntax { AutolinkSyntax() : super(r'<(([a-zA-Z][a-zA-Z\-\+\.]+):(?://)?[^\s>]*)>');
diff --git a/pkgs/markdown/tool/common_mark_stats.json b/pkgs/markdown/tool/common_mark_stats.json index cdcda4c..bfa5c58 100644 --- a/pkgs/markdown/tool/common_mark_stats.json +++ b/pkgs/markdown/tool/common_mark_stats.json
@@ -30,8 +30,8 @@ "572": "strict", "573": "loose", "574": "strict", - "575": "fail", - "576": "fail", + "575": "strict", + "576": "strict", "577": "loose", "578": "loose", "579": "loose",
diff --git a/pkgs/markdown/tool/common_mark_stats.txt b/pkgs/markdown/tool/common_mark_stats.txt index 78f591a..b854444 100644 --- a/pkgs/markdown/tool/common_mark_stats.txt +++ b/pkgs/markdown/tool/common_mark_stats.txt
@@ -1,5 +1,5 @@ 15 of 18 – 83.3% ATX headings - 17 of 19 – 89.5% Autolinks + 19 of 19 – 100.0% Autolinks 9 of 13 – 69.2% Backslash escapes 1 of 1 – 100.0% Blank lines 22 of 25 – 88.0% Block quotes @@ -24,4 +24,4 @@ 6 of 11 – 54.5% Tabs 3 of 3 – 100.0% Textual content 17 of 19 – 89.5% Thematic breaks - 502 of 624 – 80.4% TOTAL + 504 of 624 – 80.8% TOTAL
diff --git a/pkgs/markdown/tool/gfm_stats.json b/pkgs/markdown/tool/gfm_stats.json index 41ae33a..a0675a3 100644 --- a/pkgs/markdown/tool/gfm_stats.json +++ b/pkgs/markdown/tool/gfm_stats.json
@@ -30,8 +30,8 @@ "584": "strict", "585": "loose", "586": "strict", - "587": "fail", - "588": "fail", + "587": "strict", + "588": "strict", "589": "loose", "590": "loose", "591": "loose",
diff --git a/pkgs/markdown/tool/gfm_stats.txt b/pkgs/markdown/tool/gfm_stats.txt index c377c61..7582c75 100644 --- a/pkgs/markdown/tool/gfm_stats.txt +++ b/pkgs/markdown/tool/gfm_stats.txt
@@ -1,5 +1,5 @@ 5 of 18 – 27.8% ATX headings - 17 of 19 – 89.5% Autolinks + 19 of 19 – 100.0% Autolinks 0 of 11 – 0.0% Autolinks (extension) 9 of 13 – 69.2% Backslash escapes 0 of 1 – 0.0% Blank lines @@ -28,4 +28,4 @@ 5 of 11 – 45.5% Tabs 3 of 3 – 100.0% Textual content 16 of 19 – 84.2% Thematic breaks - 470 of 646 – 72.8% TOTAL + 472 of 646 – 73.1% TOTAL