Fix beginning of line detection in `AutolinkExtensionSyntax` (dart-lang/markdown#555)
diff --git a/pkgs/markdown/CHANGELOG.md b/pkgs/markdown/CHANGELOG.md index 6f275c9..3cd2f7a 100644 --- a/pkgs/markdown/CHANGELOG.md +++ b/pkgs/markdown/CHANGELOG.md
@@ -1,6 +1,7 @@ ## 7.1.2-wip * Update all CommonMark specification links to 0.30. +* Fix beginning of line detection in `AutolinkExtensionSyntax`. ## 7.1.1
diff --git a/pkgs/markdown/lib/src/inline_syntaxes/autolink_extension_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/autolink_extension_syntax.dart index 85773dc..0333abb 100644 --- a/pkgs/markdown/lib/src/inline_syntaxes/autolink_extension_syntax.dart +++ b/pkgs/markdown/lib/src/inline_syntaxes/autolink_extension_syntax.dart
@@ -60,12 +60,12 @@ return false; } - // When it is a link and it is not preceded by `*`, `_`, `~`, `(`, or `>`, - // it is invalid. See - // https://github.github.com/gfm/#extended-autolink-path-validation. + // When it is a link and it is not at the beginning of a line, or preceded + // by whitespace, `*`, `_`, `~`, `(`, or `>`, it is invalid. See + // https://github.github.com/gfm/#autolinks-extension-. if (startMatch[1] != null && parser.pos > 0) { final precededBy = String.fromCharCode(parser.charAt(parser.pos - 1)); - const validPrecedingChars = {' ', '*', '_', '~', '(', '>'}; + const validPrecedingChars = {'\n', ' ', '*', '_', '~', '(', '>'}; if (!validPrecedingChars.contains(precededBy)) { return false; }
diff --git a/pkgs/markdown/test/extensions/autolink_extension.unit b/pkgs/markdown/test/extensions/autolink_extension.unit index 8ab4613..4a07fdc 100644 --- a/pkgs/markdown/test/extensions/autolink_extension.unit +++ b/pkgs/markdown/test/extensions/autolink_extension.unit
@@ -1,4 +1,10 @@ >>> not a link mhttp://www.foo.com <<< -<p>mhttp://www.foo.com</p> \ No newline at end of file +<p>mhttp://www.foo.com</p> +>>> following a newline +m +http://www.foo.com +<<< +<p>m +<a href="http://www.foo.com">http://www.foo.com</a></p> \ No newline at end of file