diff --git a/.changeset/fix_spoilers_breaking_when_using_a_proxy_tagshorthand.md b/.changeset/fix_spoilers_breaking_when_using_a_proxy_tagshorthand.md new file mode 100644 index 000000000..9b090163c --- /dev/null +++ b/.changeset/fix_spoilers_breaking_when_using_a_proxy_tagshorthand.md @@ -0,0 +1,5 @@ +--- +default: patch +--- + +# Fix spoilers breaking when using a proxy tag/shorthand diff --git a/src/app/components/editor/output.ts b/src/app/components/editor/output.ts index 6c3665925..ef2ef4428 100644 --- a/src/app/components/editor/output.ts +++ b/src/app/components/editor/output.ts @@ -170,15 +170,20 @@ const SPOILEREDLINKDIRECTREGEX = new RegExp(`\\|\\|(${LINK_URL})\\|\\|`, 'g'); export const toPlainText = ( node: Descendant | Descendant[], stripNickname = false, + stripSpoilers = true, nickNameReplacement?: Map ): string => { if (Array.isArray(node)) - return node.map((n) => toPlainText(n, stripNickname, nickNameReplacement)).join(''); + return node + .map((n) => toPlainText(n, stripNickname, stripSpoilers, nickNameReplacement)) + .join(''); if (Text.isText(node)) { let { text } = node; - text = text.replaceAll(SPOILERINPUTREGEX, '[Spoiler]'); - text = text.replaceAll(SPOILEREDLINKINPUTREGEX, '$1'); + if (stripSpoilers) { + text = text.replaceAll(SPOILERINPUTREGEX, '[Spoiler]'); + text = text.replaceAll(SPOILEREDLINKINPUTREGEX, '$1'); + } if (stripNickname && nickNameReplacement) { for (const [key, replacement] of nickNameReplacement) { @@ -189,7 +194,7 @@ export const toPlainText = ( } const children = node.children - .map((n) => toPlainText(n, stripNickname, nickNameReplacement)) + .map((n) => toPlainText(n, stripNickname, stripSpoilers, nickNameReplacement)) .join(''); return elementToPlainText(node, children); }; diff --git a/src/app/features/room/RoomInput.tsx b/src/app/features/room/RoomInput.tsx index bedea1a1f..3b07fe1e7 100644 --- a/src/app/features/room/RoomInput.tsx +++ b/src/app/features/room/RoomInput.tsx @@ -1253,7 +1253,7 @@ export const RoomInput = forwardRef( serializedChildren = transform.apply(serializedChildren, outgoingTransformContext); }); - let plainText = toPlainText(serializedChildren, true, nicknameReplacement).trim(); + let plainText = toPlainText(serializedChildren, true, true, nicknameReplacement).trim(); /** * the html we will send @@ -1327,7 +1327,16 @@ export const RoomInput = forwardRef( proxiedPerMessageProfile = await pluralkitProxyMessageHandler.getPmpBasedOnMessage(plainText); if (proxiedPerMessageProfile) { - const stripped = pluralkitProxyMessageHandler.stripProxyFromMessage(plainText); + // normal plainText has spoilers stripped, but this breaks spoilers with a proxy tag. + // here we get a new 'unsanitized' plainText without spoiler stripping + let unsanitizedPlainText = toPlainText( + serializedChildren, + true, + false, + nicknameReplacement + ).trim(); + + const stripped = pluralkitProxyMessageHandler.stripProxyFromMessage(unsanitizedPlainText); if (stripped !== undefined) { // Re-run the normal outgoing pipeline on the stripped content so the message // goes through the same transforms/parsers as any other message. @@ -1338,7 +1347,7 @@ export const RoomInput = forwardRef( serializedChildren = transform.apply(serializedChildren, outgoingTransformContext); }); - plainText = toPlainText(serializedChildren, true, nicknameReplacement).trim(); + plainText = toPlainText(serializedChildren, true, true, nicknameReplacement).trim(); customHtml = trimCustomHtml( toMatrixCustomHTML(serializedChildren, { stripNickname: true,