Parenthesis fixes.

This commit is contained in:
flash 2025-05-19 11:33:10 +00:00
parent 911bf2f934
commit c4872f1fc0
Signed by: flash
GPG key ID: 2C9C2C574D47FE3E

View file

@ -254,8 +254,13 @@ Umi.UI.Messages = (function() {
continue; continue;
let offset = 0; 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) { for(let part of parts) {
while(part.startsWith('(') && part.endsWith(')')) {
offset += 1;
part = part.substring(1, part.length - 1);
}
const noProto = part.startsWith('//'); const noProto = part.startsWith('//');
if(!noProto && !part.includes('://')) { if(!noProto && !part.includes('://')) {
offset += part.length; offset += part.length;
@ -275,20 +280,20 @@ Umi.UI.Messages = (function() {
offset = 0; offset = 0;
} }
let text = part; const length = part.length;
while(!text.endsWith('/') && /\p{P}$/u.test(text)) while(!part.endsWith('/') && /\p{Po}$/u.test(part))
text = text.substring(0, text.length - 1); part = part.substring(0, part.length - 1);
if(text.length < part.length) { if(part.length < length) {
url = new URL(noProto ? (location.protocol + text) : text); url = new URL(noProto ? (location.protocol + part) : part);
offset += part.length - text.length; offset += length - part.length;
} }
const replaceNode = childNode; const replaceNode = childNode;
childNode = replaceNode.splitText(text.length); childNode = replaceNode.splitText(part.length);
replaceNode.replaceWith(<a class="markup__link" href={url.toString()} target="_blank" rel="nofollow noreferrer noopener"> replaceNode.replaceWith(<a class="markup__link" href={url.toString()} target="_blank" rel="nofollow noreferrer noopener">
{decodeURI(text)} {decodeURIComponent(part)}
</a>); </a>);
} }
} finally { } finally {