From 0d9191ed5c9429e8acf0bdee7955fcddcec7092a Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Tue, 29 Aug 2023 01:36:15 +1200 Subject: [PATCH] m->d support spoilers --- m2d/converters/event-to-message.js | 10 +++++++++ m2d/converters/event-to-message.test.js | 30 +++++++++++++++++++++++++ notes.md | 5 ++--- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/m2d/converters/event-to-message.js b/m2d/converters/event-to-message.js index 92e5ca4..9c221a5 100644 --- a/m2d/converters/event-to-message.js +++ b/m2d/converters/event-to-message.js @@ -57,6 +57,16 @@ turndownService.addRule("blockquote", { } }) +turndownService.addRule("spoiler", { + filter: function (node, options) { + return node.hasAttribute("data-mx-spoiler") + }, + + replacement: function (content, node) { + return "||" + content + "||" + } +}) + turndownService.addRule("inlineLink", { filter: function (node, options) { return ( diff --git a/m2d/converters/event-to-message.test.js b/m2d/converters/event-to-message.test.js index d071f8d..41bb2e7 100644 --- a/m2d/converters/event-to-message.test.js +++ b/m2d/converters/event-to-message.test.js @@ -120,6 +120,36 @@ test("event2message: basic html is converted to markdown", async t => { ) }) +test("event2message: spoilers work", async t => { + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: `this is a test of spoilers` + }, + event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU", + origin_server_ts: 1688301929913, + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", + sender: "@cadence:cadence.moe", + type: "m.room.message", + unsigned: { + age: 405299 + } + }), + { + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "this **is** a ||_test_|| of ||spoilers||", + avatar_url: undefined + }] + } + ) +}) + test("event2message: markdown syntax is escaped", async t => { t.deepEqual( await eventToMessage({ diff --git a/notes.md b/notes.md index aa9066d..e701760 100644 --- a/notes.md +++ b/notes.md @@ -3,13 +3,12 @@ ## Known issues - m->d attachments do not work -- m->d edits do not work -- m->d spoilers do not work - d->m support the rest of the attachments by reading the matrix spec instead of the current approach of whitelisting mime types - d->m emojis do not work at all (inline chat, single emoji size, reactions, bridged state) - m->d code blocks have slightly too much spacing - m->d some reactions don't work because of the variation selector -- <--> check whether I implemented deletions +- d->m check whether I implemented deletions +- m->d deletions - rooms will be set up even if the bridge does not have permission for them, then break when it restarts and tries to reach messages - test private threads as part of this - solution part 1: calculate the permissions to see if the bot should be able to do stuff