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({

19
package-lock.json generated
View file

@ -15,9 +15,11 @@
"@cloudrac3r/html-template-tag": "^5.0.1",
"@cloudrac3r/mixin-deep": "^3.0.0",
"@cloudrac3r/pngjs": "^7.0.3",
"@cloudrac3r/turndown": "^7.1.4",
"better-sqlite3": "^9.0.0",
"chunk-text": "^2.0.1",
"cloudstorm": "^0.10.8",
"domino": "^2.1.6",
"entities": "^4.5.0",
"get-stream": "^6.0.1",
"heatsync": "^2.5.3",
@ -30,7 +32,6 @@
"snowtransfer": "^0.10.5",
"stream-mime-type": "^1.0.2",
"try-to-catch": "^3.0.1",
"turndown": "^7.1.2",
"xxhash-wasm": "^1.0.2"
},
"devDependencies": {
@ -213,6 +214,14 @@
"node": ">=8.0.0"
}
},
"node_modules/@cloudrac3r/turndown": {
"version": "7.1.4",
"resolved": "https://registry.npmjs.org/@cloudrac3r/turndown/-/turndown-7.1.4.tgz",
"integrity": "sha512-bQAwcvcSqBTdEHPMt+IAZWIoDh+2eRuy9TgD0FUdxVurbvj3CUHTxLfzlmsO0UTi+GHpgYqDSsVdV7kYTNq5Qg==",
"dependencies": {
"domino": "^2.1.6"
}
},
"node_modules/@isaacs/cliui": {
"version": "8.0.2",
"resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz",
@ -3100,14 +3109,6 @@
"node": "*"
}
},
"node_modules/turndown": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/turndown/-/turndown-7.1.2.tgz",
"integrity": "sha512-ntI9R7fcUKjqBP6QU8rBK2Ehyt8LAzt3UBT9JR9tgo6GtuKvyUzpayWmeMKJw1DPdXzktvtIT8m2mVXz+bL/Qg==",
"dependencies": {
"domino": "^2.1.6"
}
},
"node_modules/type-is": {
"version": "1.6.18",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",

View file

@ -21,9 +21,11 @@
"@cloudrac3r/html-template-tag": "^5.0.1",
"@cloudrac3r/mixin-deep": "^3.0.0",
"@cloudrac3r/pngjs": "^7.0.3",
"@cloudrac3r/turndown": "^7.1.4",
"better-sqlite3": "^9.0.0",
"chunk-text": "^2.0.1",
"cloudstorm": "^0.10.8",
"domino": "^2.1.6",
"entities": "^4.5.0",
"get-stream": "^6.0.1",
"heatsync": "^2.5.3",
@ -36,7 +38,6 @@
"snowtransfer": "^0.10.5",
"stream-mime-type": "^1.0.2",
"try-to-catch": "^3.0.1",
"turndown": "^7.1.2",
"xxhash-wasm": "^1.0.2"
},
"devDependencies": {