fix(tui): prevent duplicate URL display for autolinked emails (#888)

Autolinked emails like user@example.com were rendered as
'user@example.com (mailto:user@example.com)' because the comparison
token.text === token.href failed (text lacks mailto: prefix).

Now strips mailto: prefix before comparing, so autolinked emails
display without redundant URL in parentheses.
This commit is contained in:
Michael Renner 2026-01-21 23:20:00 +01:00 committed by GitHub
parent 0363a10c69
commit 620239bd3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 58 additions and 1 deletions

View file

@ -379,7 +379,10 @@ export class Markdown implements Component {
const linkText = this.renderInlineTokens(token.tokens || []);
// If link text matches href, only show the link once
// Compare raw text (token.text) not styled text (linkText) since linkText has ANSI codes
if (token.text === token.href) {
// For mailto: links, strip the prefix before comparing (autolinked emails have
// text="foo@bar.com" but href="mailto:foo@bar.com")
const hrefForComparison = token.href.startsWith("mailto:") ? token.href.slice(7) : token.href;
if (token.text === token.href || token.text === hrefForComparison) {
result += this.theme.link(this.theme.underline(linkText)) + this.getDefaultStylePrefix();
} else {
result +=