Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/discord-bare-url-links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chat-adapter/discord": patch
---

fix: render bare URLs and autolinks as bare URLs instead of `[url](url)` masked links, which Discord only renders inside embeds (in normal messages they showed up as literal text)
20 changes: 20 additions & 0 deletions packages/adapter-discord/src/markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ describe("DiscordFormatConverter", () => {
expect(result).toContain("[link text](https://example.com)");
});

it("should render a bare URL as a bare URL, not a masked link", () => {
// Discord renders masked links `[text](url)` only in embeds, so wrapping
// a bare URL as `[url](url)` shows up as literal text in a normal message.
const ast = converter.toAst("https://example.com");
const result = converter.fromAst(ast);
expect(result).toContain("https://example.com");
expect(result).not.toContain(
"[https://example.com](https://example.com)"
);
});

it("should render an autolink as a bare URL, not a masked link", () => {
const ast = converter.toAst("<https://example.com>");
const result = converter.fromAst(ast);
expect(result).toContain("https://example.com");
expect(result).not.toContain(
"[https://example.com](https://example.com)"
);
});

it("should preserve inline code", () => {
const ast = converter.toAst("Use `const x = 1`");
const result = converter.fromAst(ast);
Expand Down
6 changes: 6 additions & 0 deletions packages/adapter-discord/src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ export class DiscordFormatConverter extends BaseFormatConverter {
const linkText = getNodeChildren(node)
.map((child) => this.nodeToDiscordMarkdown(child))
.join("");
// Bare URLs / autolinks (label === url) must stay bare: Discord only
// renders masked links `[text](url)` inside embeds, so `[url](url)` in a
// normal message shows up as literal text instead of a clickable link.
if (linkText === node.url) {
return node.url;
}
// Standard markdown [text](url)
return `[${linkText}](${node.url})`;
}
Expand Down