Fork turndown for Discord-like link escaping

This commit is contained in:
Cadence Ember 2024-07-30 23:45:44 +12:00
parent a6251e850c
commit 742d34f15e
4 changed files with 52 additions and 11 deletions

View file

@ -4,7 +4,7 @@ const Ty = require("../../types")
const DiscordTypes = require("discord-api-types/v10")
const {Readable} = require("stream")
const chunk = require("chunk-text")
const TurndownService = require("turndown")
const TurndownService = require("@cloudrac3r/turndown")
const domino = require("domino")
const assert = require("assert").strict
const entities = require("entities")

View file

@ -263,6 +263,45 @@ test("event2message: links in formatted body where the text & href are the same,
)
})
test("event2message: markdown in link text does not attempt to be escaped because that doesn't work", async t => {
t.deepEqual(
await eventToMessage({
content: {
body: "hey mario sports mix [she/her], is it possible to listen on a unix socket?",
format: "org.matrix.custom.html",
formatted_body: "hey <a href=\"https://matrix.to/#/%40cadence%3Acadence.moe\">mario sports mix [she/her]</a>, is it possible to listen on a unix socket?",
"m.mentions": {
"user_ids": [
"@cadence:cadence.moe"
]
},
msgtype: "m.text"
},
event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU",
origin_server_ts: 1688301929913,
room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe",
sender: "@cadence:cadence.moe",
type: "m.room.message",
unsigned: {
age: 405299
}
}),
{
ensureJoined: [],
messagesToDelete: [],
messagesToEdit: [],
messagesToSend: [{
username: "cadence [they]",
content: "hey [mario sports mix [she/her]](<https://matrix.to/#/%40cadence%3Acadence.moe>), is it possible to listen on a unix socket?",
avatar_url: undefined,
allowed_mentions: {
parse: ["users", "roles"]
}
}]
}
)
})
test("event2message: basic html is converted to markdown", async t => {
t.deepEqual(
await eventToMessage({