Further improvements to autolinking.
This commit is contained in:
parent
14f9eab077
commit
b19490e367
1 changed files with 24 additions and 15 deletions
|
@ -251,30 +251,39 @@ Umi.UI.Messages = (function() {
|
|||
continue;
|
||||
|
||||
let offset = 0;
|
||||
const parts = childNode.data.split(/(\p{White_Space}+)/u);
|
||||
const parts = childNode.data.split(/([\p{White_Space}(){}\[\]<>'"]+)/u);
|
||||
for(const part of parts) {
|
||||
if(!part.startsWith('//') && !part.includes('://')) {
|
||||
offset += part.length;
|
||||
continue;
|
||||
}
|
||||
|
||||
let url;
|
||||
try {
|
||||
const url = (new URL(part)).toString();
|
||||
|
||||
if(offset > 0) {
|
||||
childNode = childNode.splitText(offset);
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
const replaceNode = childNode;
|
||||
childNode = replaceNode.splitText(part.length);
|
||||
|
||||
replaceNode.replaceWith(<a class="markup__link" href={url} target="_blank" rel="nofollow noreferrer noopener">
|
||||
{decodeURI(url)}
|
||||
</a>);
|
||||
url = new URL(part);
|
||||
} catch(ex) {
|
||||
offset += part.length;
|
||||
offset += addToOffset;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(offset > 0) {
|
||||
childNode = childNode.splitText(offset);
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
let text = part;
|
||||
while(!text.endsWith('/') && /\p{P}$/u.test(text))
|
||||
text = text.substring(0, text.length - 1);
|
||||
|
||||
if(text.length < part.length)
|
||||
url = new URL(text);
|
||||
|
||||
const replaceNode = childNode;
|
||||
childNode = replaceNode.splitText(text.length);
|
||||
|
||||
replaceNode.replaceWith(<a class="markup__link" href={url.toString()} target="_blank" rel="nofollow noreferrer noopener">
|
||||
{decodeURI(text)}
|
||||
</a>);
|
||||
}
|
||||
} finally {
|
||||
childNode = childNode.nextSibling;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue