diff --git a/lib/shared/markdown.js b/lib/shared/markdown.js --- a/lib/shared/markdown.js +++ b/lib/shared/markdown.js @@ -252,6 +252,10 @@ const spoilerRegex: RegExp = /^\|\|([^\n]+?)\|\|/g; +function hideSpoilerText(text: string): string { + return text.replace(/\|\|(.+?)\|\|/g, '⬛⬛⬛'); +} + export { paragraphRegex, paragraphStripTrailingNewlineRegex, @@ -272,4 +276,5 @@ matchList, parseList, matchMentions, + hideSpoilerText, }; diff --git a/lib/shared/messages/text-message-spec.js b/lib/shared/messages/text-message-spec.js --- a/lib/shared/messages/text-message-spec.js +++ b/lib/shared/messages/text-message-spec.js @@ -16,7 +16,7 @@ import type { NotifTexts } from '../../types/notif-types'; import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; -import { type ASTNode, type SingleASTNode } from '../markdown'; +import { type ASTNode, type SingleASTNode, hideSpoilerText } from '../markdown'; import { threadIsGroupChat } from '../thread-utils'; import { stringForUser } from '../user-utils'; import type { @@ -84,9 +84,9 @@ messageTitle({ messageInfo, markdownRules }) { const { text } = messageInfo; + const textWithoutSpoilers = hideSpoilerText(text); const parser = SimpleMarkdown.parserFor(markdownRules); - const ast = parser(text, { disableAutoBlockNewlines: true }); - + const ast = parser(textWithoutSpoilers, { disableAutoBlockNewlines: true }); return getFirstNonQuotedRawLine(ast).trim(); },