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:
@@ -532,13 +532,24 @@ function _linkify_content(content, new_window) {
|
|||||||
return '<a href="' + url + '"' + target + '>' + url + '</a>' + trailing;
|
return '<a href="' + url + '"' + target + '>' + url + '</a>' + trailing;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Then, replace domain-like text (but not if already inside an href)
|
// Then, replace domain-like text only in segments NOT inside <a> tags
|
||||||
content = content.replace(domain_pattern, (match) => {
|
// (the URL replacement above may have created <a> tags)
|
||||||
// Clean trailing punctuation
|
const link_pattern = /(<a\s[^>]*>.*?<\/a>)/gi;
|
||||||
const domain = match.replace(/[.,;:!?)'\"]+$/, '');
|
const segments = content.split(link_pattern);
|
||||||
const trailing = match.slice(domain.length);
|
|
||||||
return '<a href="https://' + domain + '"' + target + '>' + domain + '</a>' + trailing;
|
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;
|
return content;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1659,14 +1659,26 @@ function _linkify_content(string $content, bool $new_window): string
|
|||||||
return '<a href="' . $url . '"' . $target . '>' . $url . '</a>';
|
return '<a href="' . $url . '"' . $target . '>' . $url . '</a>';
|
||||||
}, $content);
|
}, $content);
|
||||||
|
|
||||||
// Then, replace domain-like text (but not if already inside an href)
|
// Then, replace domain-like text only in segments NOT inside <a> tags
|
||||||
$content = preg_replace_callback($domain_pattern, function ($matches) use ($target) {
|
// (the URL replacement above may have created <a> tags)
|
||||||
$domain = $matches[1];
|
$link_pattern = '/(<a\s[^>]*>.*?<\/a>)/is';
|
||||||
// Clean trailing punctuation
|
$segments = preg_split($link_pattern, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||||
$domain = rtrim($domain, '.,;:!?)\'\"');
|
|
||||||
// Don't linkify if it looks like it's already in an href attribute
|
|
||||||
return '<a href="https://' . $domain . '"' . $target . '>' . $domain . '</a>';
|
|
||||||
}, $content);
|
|
||||||
|
|
||||||
return $content;
|
$result = '';
|
||||||
|
foreach ($segments as $segment) {
|
||||||
|
// Skip segments that are already links
|
||||||
|
if (preg_match('/^<a\s/i', $segment)) {
|
||||||
|
$result .= $segment;
|
||||||
|
} else {
|
||||||
|
// Apply domain pattern to non-link segments
|
||||||
|
$result .= preg_replace_callback($domain_pattern, function ($matches) use ($target) {
|
||||||
|
$domain = $matches[1];
|
||||||
|
// Clean trailing punctuation
|
||||||
|
$domain = rtrim($domain, '.,;:!?)\'\"');
|
||||||
|
return '<a href="https://' . $domain . '"' . $target . '>' . $domain . '</a>';
|
||||||
|
}, $segment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user