webmail: better recognize URLs in text wrapped in () or <> if it follows interpunction

e.g. "text... (https://localhost)." would keep ) as part of the url before, but not anymore.
This commit is contained in:
Mechiel Lukkien 2023-09-21 11:09:27 +02:00
parent d649cf7dc2
commit d07c871f5c
No known key found for this signature in database
4 changed files with 35 additions and 12 deletions

View File

@ -242,9 +242,14 @@ const addLinks = (text: string): (HTMLAnchorElement | string)[] => {
r.push(s) r.push(s)
// If URL ends with interpunction, and next character is whitespace or end, don't // If URL ends with interpunction, and next character is whitespace or end, don't
// include the interpunction in the URL. // include the interpunction in the URL.
if (/[!),.:;>?]$/.test(url) && (!text || /^[ \t\r\n]/.test(text))) { if (!text || /^[ \t\r\n]/.test(text)) {
text = url.substring(url.length-1)+text if (/[)>][!,.:;?]$/.test(url)) {
url = url.substring(0, url.length-1) text = url.substring(url.length-2)+text
url = url.substring(0, url.length-2)
} else if (/[)>!,.:;?]$/.test(url)) {
text = url.substring(url.length-1)+text
url = url.substring(0, url.length-1)
}
} }
r.push(dom.a(url, attr.href(url), attr.target('_blank'), attr.rel('noopener noreferrer'))) r.push(dom.a(url, attr.href(url), attr.target('_blank'), attr.rel('noopener noreferrer')))
} }

View File

@ -864,9 +864,15 @@ const addLinks = (text) => {
r.push(s); r.push(s);
// If URL ends with interpunction, and next character is whitespace or end, don't // If URL ends with interpunction, and next character is whitespace or end, don't
// include the interpunction in the URL. // include the interpunction in the URL.
if (/[!),.:;>?]$/.test(url) && (!text || /^[ \t\r\n]/.test(text))) { if (!text || /^[ \t\r\n]/.test(text)) {
text = url.substring(url.length - 1) + text; if (/[)>][!,.:;?]$/.test(url)) {
url = url.substring(0, url.length - 1); text = url.substring(url.length - 2) + text;
url = url.substring(0, url.length - 2);
}
else if (/[)>!,.:;?]$/.test(url)) {
text = url.substring(url.length - 1) + text;
url = url.substring(0, url.length - 1);
}
} }
r.push(dom.a(url, attr.href(url), attr.target('_blank'), attr.rel('noopener noreferrer'))); r.push(dom.a(url, attr.href(url), attr.target('_blank'), attr.rel('noopener noreferrer')));
} }

View File

@ -864,9 +864,15 @@ const addLinks = (text) => {
r.push(s); r.push(s);
// If URL ends with interpunction, and next character is whitespace or end, don't // If URL ends with interpunction, and next character is whitespace or end, don't
// include the interpunction in the URL. // include the interpunction in the URL.
if (/[!),.:;>?]$/.test(url) && (!text || /^[ \t\r\n]/.test(text))) { if (!text || /^[ \t\r\n]/.test(text)) {
text = url.substring(url.length - 1) + text; if (/[)>][!,.:;?]$/.test(url)) {
url = url.substring(0, url.length - 1); text = url.substring(url.length - 2) + text;
url = url.substring(0, url.length - 2);
}
else if (/[)>!,.:;?]$/.test(url)) {
text = url.substring(url.length - 1) + text;
url = url.substring(0, url.length - 1);
}
} }
r.push(dom.a(url, attr.href(url), attr.target('_blank'), attr.rel('noopener noreferrer'))); r.push(dom.a(url, attr.href(url), attr.target('_blank'), attr.rel('noopener noreferrer')));
} }

View File

@ -864,9 +864,15 @@ const addLinks = (text) => {
r.push(s); r.push(s);
// If URL ends with interpunction, and next character is whitespace or end, don't // If URL ends with interpunction, and next character is whitespace or end, don't
// include the interpunction in the URL. // include the interpunction in the URL.
if (/[!),.:;>?]$/.test(url) && (!text || /^[ \t\r\n]/.test(text))) { if (!text || /^[ \t\r\n]/.test(text)) {
text = url.substring(url.length - 1) + text; if (/[)>][!,.:;?]$/.test(url)) {
url = url.substring(0, url.length - 1); text = url.substring(url.length - 2) + text;
url = url.substring(0, url.length - 2);
}
else if (/[)>!,.:;?]$/.test(url)) {
text = url.substring(url.length - 1) + text;
url = url.substring(0, url.length - 1);
}
} }
r.push(dom.a(url, attr.href(url), attr.target('_blank'), attr.rel('noopener noreferrer'))); r.push(dom.a(url, attr.href(url), attr.target('_blank'), attr.rel('noopener noreferrer')));
} }