@@ -13,7 +13,9 @@ class AutolinkExtensionSyntax extends InlineSyntax {
13
13
static const _linkPattern =
14
14
// Autolinks can only come at the beginning of a line, after whitespace,
15
15
// or any of the delimiting characters *, _, ~, and (.
16
- r'(?<=^|[\s*_~(>])'
16
+ // Note: Disable this piece for now, as Safari does not support
17
+ // lookarounds. Consider re-enabling later.
18
+ // r'(?<=^|[\s*_~(>])'
17
19
18
20
// An extended url autolink will be recognised when one of the schemes
19
21
// http://, or https://, followed by a valid domain. See
@@ -35,12 +37,14 @@ class AutolinkExtensionSyntax extends InlineSyntax {
35
37
// not be considered part of the autolink, though they may be included in
36
38
// the interior of the link. See
37
39
// https://github.github.com/gfm/#extended-autolink-path-validation.
38
- '(?<![?!.,:*_~])' ;
40
+ // Note: Do not use negative lookbehind, as Safari does not support it.
41
+ // '(?<![?!.,:*_~])'
42
+ r'[^\s<?!.,:*_~]' ;
39
43
40
44
// An extended email autolink, see
41
45
// https://github.github.com/gfm/#extended-email-autolink.
42
46
static const _emailPattern =
43
- r'[-_.+a-z0-9]+@(?:[-_a-z0-9]+\.)+[-_a-z0-9]*[a-z0-9](?![-_]) ' ;
47
+ r'[-_.+a-z0-9]+@(?:[-_a-z0-9]+\.)+[-_a-z0-9]*[a-z0-9]' ;
44
48
45
49
AutolinkExtensionSyntax ()
46
50
: super (
@@ -55,6 +59,28 @@ class AutolinkExtensionSyntax extends InlineSyntax {
55
59
if (startMatch == null ) {
56
60
return false ;
57
61
}
62
+
63
+ // When it is a link and it is not preceded by `*`, `_`, `~`, `(`, or `>`,
64
+ // it is invalid. See
65
+ // https://github.github.com/gfm/#extended-autolink-path-validation.
66
+ if (startMatch[1 ] != null && parser.pos > 0 ) {
67
+ final precededBy = String .fromCharCode (parser.charAt (parser.pos - 1 ));
68
+ const validPrecedingChars = {' ' , '*' , '_' , '~' , '(' , '>' };
69
+ if (validPrecedingChars.contains (precededBy) == false ) {
70
+ return false ;
71
+ }
72
+ }
73
+
74
+ // When it is an email link and followed by `_` or `-`, it is invalid. See
75
+ // https://github.github.com/gfm/#example-633
76
+ if (startMatch[2 ] != null && parser.source.length > startMatch.end) {
77
+ final followedBy = String .fromCharCode (parser.charAt (startMatch.end));
78
+ const invalidFollowingChars = {'_' , '-' };
79
+ if (invalidFollowingChars.contains (followedBy)) {
80
+ return false ;
81
+ }
82
+ }
83
+
58
84
parser.writeText ();
59
85
return onMatch (parser, startMatch);
60
86
}
0 commit comments