Fix m->d double-escaping of Matrix mentions

This commit is contained in:
Cadence Ember
2026-02-03 22:26:00 +13:00
parent 15aa6ed502
commit 238e911d13

View File

@@ -138,7 +138,9 @@ turndownService.addRule("inlineLink", {
if (node.getAttribute("data-message-id")) return `https://discord.com/channels/${node.getAttribute("data-guild-id")}/${node.getAttribute("data-channel-id")}/${node.getAttribute("data-message-id")}`
if (node.getAttribute("data-channel-id")) return `<#${node.getAttribute("data-channel-id")}>`
const href = node.getAttribute("href")
const suppressedHref = node.hasAttribute("data-suppress") ? "<" + href + ">" : href
let shouldSuppress = node.hasAttribute("data-suppress")
if (href.match(/^https?:\/\/matrix.to\//)) shouldSuppress = false // avoid double-escaping
const suppressedHref = shouldSuppress ? "<" + href + ">" : href
content = content.replace(/ @.*/, "")
if (href === content) return suppressedHref
if (decodeURIComponent(href).startsWith("https://matrix.to/#/@") && content[0] !== "@") content = "@" + content