mirror of
https://github.com/mjl-/mox.git
synced 2025-04-21 21:40:01 +03:00
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:
parent
d649cf7dc2
commit
d07c871f5c
4 changed files with 35 additions and 12 deletions
|
@ -242,9 +242,14 @@ const addLinks = (text: string): (HTMLAnchorElement | string)[] => {
|
|||
r.push(s)
|
||||
// If URL ends with interpunction, and next character is whitespace or end, don't
|
||||
// include the interpunction in the URL.
|
||||
if (/[!),.:;>?]$/.test(url) && (!text || /^[ \t\r\n]/.test(text))) {
|
||||
text = url.substring(url.length-1)+text
|
||||
url = url.substring(0, url.length-1)
|
||||
if (!text || /^[ \t\r\n]/.test(text)) {
|
||||
if (/[)>][!,.:;?]$/.test(url)) {
|
||||
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')))
|
||||
}
|
||||
|
|
|
@ -864,9 +864,15 @@ const addLinks = (text) => {
|
|||
r.push(s);
|
||||
// If URL ends with interpunction, and next character is whitespace or end, don't
|
||||
// include the interpunction in the URL.
|
||||
if (/[!),.:;>?]$/.test(url) && (!text || /^[ \t\r\n]/.test(text))) {
|
||||
text = url.substring(url.length - 1) + text;
|
||||
url = url.substring(0, url.length - 1);
|
||||
if (!text || /^[ \t\r\n]/.test(text)) {
|
||||
if (/[)>][!,.:;?]$/.test(url)) {
|
||||
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')));
|
||||
}
|
||||
|
|
|
@ -864,9 +864,15 @@ const addLinks = (text) => {
|
|||
r.push(s);
|
||||
// If URL ends with interpunction, and next character is whitespace or end, don't
|
||||
// include the interpunction in the URL.
|
||||
if (/[!),.:;>?]$/.test(url) && (!text || /^[ \t\r\n]/.test(text))) {
|
||||
text = url.substring(url.length - 1) + text;
|
||||
url = url.substring(0, url.length - 1);
|
||||
if (!text || /^[ \t\r\n]/.test(text)) {
|
||||
if (/[)>][!,.:;?]$/.test(url)) {
|
||||
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')));
|
||||
}
|
||||
|
|
|
@ -864,9 +864,15 @@ const addLinks = (text) => {
|
|||
r.push(s);
|
||||
// If URL ends with interpunction, and next character is whitespace or end, don't
|
||||
// include the interpunction in the URL.
|
||||
if (/[!),.:;>?]$/.test(url) && (!text || /^[ \t\r\n]/.test(text))) {
|
||||
text = url.substring(url.length - 1) + text;
|
||||
url = url.substring(0, url.length - 1);
|
||||
if (!text || /^[ \t\r\n]/.test(text)) {
|
||||
if (/[)>][!,.:;?]$/.test(url)) {
|
||||
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')));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue