Skip to content

Commit 84beefb

Browse files
amanjhacodes55amanclaude
authored
fix: start a GFM www autolink only at a word boundary (#4166)
Co-authored-by: aman <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent eab1e48 commit 84beefb

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎src/rules.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,12 @@ const inlineGfm: Record<InlineKeys, RegExp> = {
586586
.getRegex(),
587587
_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
588588
del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,
589-
text: edit(/^(?:[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/)
589+
text: edit(/^(?:[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|wwwStart|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/)
590590
.replace('protocol', _caseInsensitiveProtocol)
591591
.replace(/emailProtocol/g, /(?:mailto|xmpp):/)
592+
// GFM: a www autolink starts only at the beginning of a line, after whitespace or after
593+
// `*`, `_`, `~` or `(`. Without lookbehind support, keep stopping at every `www.`.
594+
.replace('wwwStart', supportsLookbehind ? '(?<![^\\s*_~(])www\\.' : 'www\\.')
592595
.getRegex(),
593596
};
594597

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<p>xwww.example.com</p>
2+
3+
<p>a.www.example.com</p>
4+
5+
<p>&lt;www.example.com&gt;</p>
6+
7+
<p>visit <a href="http://www.example.com">www.example.com</a></p>
8+
9+
<p><em><a href="http://www.example.com">www.example.com</a></em></p>
10+
11+
<p>(<a href="http://www.example.com">www.example.com</a>)</p>
12+
13+
<p><em><a href="http://www.example.com">www.example.com</a></em></p>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
xwww.example.com
2+
3+
a.www.example.com
4+
5+
<www.example.com>
6+
7+
visit www.example.com
8+
9+
*www.example.com*
10+
11+
(www.example.com)
12+
13+
_www.example.com_

0 commit comments

Comments
 (0)