mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
fix: start a GFM www autolink only at a word boundary (#4166)
Co-authored-by: aman <aman@pronnel.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
aman
Claude Opus 5.5
parent
eab1e483fe
commit
84beefb3eb
+4
-1
@@ -586,9 +586,12 @@ const inlineGfm: Record<InlineKeys, RegExp> = {
|
||||
.getRegex(),
|
||||
_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
|
||||
del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,
|
||||
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.!#$%&'*+\/=?_`{\|}~-]+@))))/)
|
||||
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.!#$%&'*+\/=?_`{\|}~-]+@))))/)
|
||||
.replace('protocol', _caseInsensitiveProtocol)
|
||||
.replace(/emailProtocol/g, /(?:mailto|xmpp):/)
|
||||
// GFM: a www autolink starts only at the beginning of a line, after whitespace or after
|
||||
// `*`, `_`, `~` or `(`. Without lookbehind support, keep stopping at every `www.`.
|
||||
.replace('wwwStart', supportsLookbehind ? '(?<![^\\s*_~(])www\\.' : 'www\\.')
|
||||
.getRegex(),
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<p>xwww.example.com</p>
|
||||
|
||||
<p>a.www.example.com</p>
|
||||
|
||||
<p><www.example.com></p>
|
||||
|
||||
<p>visit <a href="http://www.example.com">www.example.com</a></p>
|
||||
|
||||
<p><em><a href="http://www.example.com">www.example.com</a></em></p>
|
||||
|
||||
<p>(<a href="http://www.example.com">www.example.com</a>)</p>
|
||||
|
||||
<p><em><a href="http://www.example.com">www.example.com</a></em></p>
|
||||
@@ -0,0 +1,13 @@
|
||||
xwww.example.com
|
||||
|
||||
a.www.example.com
|
||||
|
||||
<www.example.com>
|
||||
|
||||
visit www.example.com
|
||||
|
||||
*www.example.com*
|
||||
|
||||
(www.example.com)
|
||||
|
||||
_www.example.com_
|
||||
Reference in New Issue
Block a user