mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 21:03:56 +00:00
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:
parent
0363a10c69
commit
620239bd3f
3 changed files with 58 additions and 1 deletions
|
|
@ -644,6 +644,56 @@ again, hello world`,
|
|||
});
|
||||
});
|
||||
|
||||
describe("Links", () => {
|
||||
it("should not duplicate URL for autolinked emails", () => {
|
||||
const markdown = new Markdown("Contact user@example.com for help", 0, 0, defaultMarkdownTheme);
|
||||
|
||||
const lines = markdown.render(80);
|
||||
const plainLines = lines.map((line) => line.replace(/\x1b\[[0-9;]*m/g, ""));
|
||||
const joinedPlain = plainLines.join(" ");
|
||||
|
||||
// Should contain the email once, not duplicated with mailto:
|
||||
assert.ok(joinedPlain.includes("user@example.com"), "Should contain email");
|
||||
assert.ok(!joinedPlain.includes("mailto:"), "Should not show mailto: prefix for autolinked emails");
|
||||
});
|
||||
|
||||
it("should not duplicate URL for bare URLs", () => {
|
||||
const markdown = new Markdown("Visit https://example.com for more", 0, 0, defaultMarkdownTheme);
|
||||
|
||||
const lines = markdown.render(80);
|
||||
const plainLines = lines.map((line) => line.replace(/\x1b\[[0-9;]*m/g, ""));
|
||||
const joinedPlain = plainLines.join(" ");
|
||||
|
||||
// URL should appear only once
|
||||
const urlCount = (joinedPlain.match(/https:\/\/example\.com/g) || []).length;
|
||||
assert.strictEqual(urlCount, 1, "URL should appear exactly once");
|
||||
});
|
||||
|
||||
it("should show URL for explicit markdown links with different text", () => {
|
||||
const markdown = new Markdown("[click here](https://example.com)", 0, 0, defaultMarkdownTheme);
|
||||
|
||||
const lines = markdown.render(80);
|
||||
const plainLines = lines.map((line) => line.replace(/\x1b\[[0-9;]*m/g, ""));
|
||||
const joinedPlain = plainLines.join(" ");
|
||||
|
||||
// Should show both link text and URL
|
||||
assert.ok(joinedPlain.includes("click here"), "Should contain link text");
|
||||
assert.ok(joinedPlain.includes("(https://example.com)"), "Should show URL in parentheses");
|
||||
});
|
||||
|
||||
it("should show URL for explicit mailto links with different text", () => {
|
||||
const markdown = new Markdown("[Email me](mailto:test@example.com)", 0, 0, defaultMarkdownTheme);
|
||||
|
||||
const lines = markdown.render(80);
|
||||
const plainLines = lines.map((line) => line.replace(/\x1b\[[0-9;]*m/g, ""));
|
||||
const joinedPlain = plainLines.join(" ");
|
||||
|
||||
// Should show both link text and mailto URL
|
||||
assert.ok(joinedPlain.includes("Email me"), "Should contain link text");
|
||||
assert.ok(joinedPlain.includes("(mailto:test@example.com)"), "Should show mailto URL in parentheses");
|
||||
});
|
||||
});
|
||||
|
||||
describe("HTML-like tags in text", () => {
|
||||
it("should render content with HTML-like tags as text", () => {
|
||||
// When the model emits something like <thinking>content</thinking> in regular text,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue