Fix linkify double-escaping URLs with protocols

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2026-01-28 18:56:04 +00:00
parent ed9bf6f23c
commit 90efeab7ea
2 changed files with 39 additions and 16 deletions

View File

@@ -532,13 +532,24 @@ function _linkify_content(content, new_window) {
return '<a href="' + url + '"' + target + '>' + url + '</a>' + trailing;
});
// Then, replace domain-like text (but not if already inside an href)
content = content.replace(domain_pattern, (match) => {
// Clean trailing punctuation
const domain = match.replace(/[.,;:!?)'\"]+$/, '');
const trailing = match.slice(domain.length);
return '<a href="https://' + domain + '"' + target + '>' + domain + '</a>' + trailing;
});
// Then, replace domain-like text only in segments NOT inside <a> tags
// (the URL replacement above may have created <a> tags)
const link_pattern = /(<a\s[^>]*>.*?<\/a>)/gi;
const segments = content.split(link_pattern);
content = segments.map(segment => {
// Skip segments that are already links
if (/^<a\s/i.test(segment)) {
return segment;
}
// Apply domain pattern to non-link segments
return segment.replace(domain_pattern, (match) => {
// Clean trailing punctuation
const domain = match.replace(/[.,;:!?)'\"]+$/, '');
const trailing = match.slice(domain.length);
return '<a href="https://' + domain + '"' + target + '>' + domain + '</a>' + trailing;
});
}).join('');
return content;
}