Skip to content

Commit 0d4e3ee

Browse files
authored
fix(discord): render bare URLs as bare links, not masked links. (#567)
## Summary Discord only renders masked links `[text](url)` inside embeds. In a normal message, a bare URL converted to `[url](url)` shows up as literal text rather than a clickable link. In nodeToDiscordMarkdown's link branch, return the bare URL when the link's label equals its target (the bare-URL / autolink case); labeled links are unchanged. Adds regression tests for both bare URLs and <autolinks>. Fixes #565.
1 parent 579ac37 commit 0d4e3ee

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@chat-adapter/discord": patch
3+
---
4+
5+
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)

packages/adapter-discord/src/markdown.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ describe("DiscordFormatConverter", () => {
2929
expect(result).toContain("[link text](https://example.com)");
3030
});
3131

32+
it("should render a bare URL as a bare URL, not a masked link", () => {
33+
// Discord renders masked links `[text](url)` only in embeds, so wrapping
34+
// a bare URL as `[url](url)` shows up as literal text in a normal message.
35+
const ast = converter.toAst("https://example.com");
36+
const result = converter.fromAst(ast);
37+
expect(result).toContain("https://example.com");
38+
expect(result).not.toContain(
39+
"[https://example.com](https://example.com)"
40+
);
41+
});
42+
43+
it("should render an autolink as a bare URL, not a masked link", () => {
44+
const ast = converter.toAst("<https://example.com>");
45+
const result = converter.fromAst(ast);
46+
expect(result).toContain("https://example.com");
47+
expect(result).not.toContain(
48+
"[https://example.com](https://example.com)"
49+
);
50+
});
51+
3252
it("should preserve inline code", () => {
3353
const ast = converter.toAst("Use `const x = 1`");
3454
const result = converter.fromAst(ast);

packages/adapter-discord/src/markdown.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ export class DiscordFormatConverter extends BaseFormatConverter {
155155
const linkText = getNodeChildren(node)
156156
.map((child) => this.nodeToDiscordMarkdown(child))
157157
.join("");
158+
// Bare URLs / autolinks (label === url) must stay bare: Discord only
159+
// renders masked links `[text](url)` inside embeds, so `[url](url)` in a
160+
// normal message shows up as literal text instead of a clickable link.
161+
if (linkText === node.url) {
162+
return node.url;
163+
}
158164
// Standard markdown [text](url)
159165
return `[${linkText}](${node.url})`;
160166
}

0 commit comments

Comments
 (0)