add test for anchor tags

This commit is contained in:
Cadence Ember 2024-02-14 21:34:31 +13:00
parent 7a9e1168fe
commit 141ae835df
2 changed files with 29 additions and 2 deletions

View file

@ -126,10 +126,10 @@ 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")
if (href === content) return href
let brackets = ["", ""]
content = content.replace(/ @.*/, "")
if (href.startsWith("https://matrix.to")) brackets = ["<", ">"]
if (href === content) return brackets[0] + href + brackets[1]
if (href.startsWith("https://matrix.to/#/@") && content[0] !== "@") content = "@" + content
return "[" + content + "](" + brackets[0] + href + brackets[1] + ")"
}