Page MenuHomePhorge

D5715.1765378832.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D5715.1765378832.diff

diff --git a/lib/shared/markdown.js b/lib/shared/markdown.js
--- a/lib/shared/markdown.js
+++ b/lib/shared/markdown.js
@@ -257,6 +257,45 @@
const stripSpoilersFromNotifications = (text: string): string =>
text.replace(replaceSpoilerRegex, spoilerReplacement);
+const stripSpoilersFromMarkdownAST = (
+ ast: SingleASTNode[],
+): SingleASTNode[] => {
+ return ast.map(node => {
+ if (Array.isArray(node)) {
+ return {
+ ...node,
+ content: stripSpoilersFromMarkdownAST(node),
+ };
+ }
+
+ const { content, items, type } = node;
+
+ if (type === 'spoiler') {
+ return {
+ type: 'text',
+ content: spoilerReplacement,
+ };
+ }
+ if (content && typeof content === 'string') {
+ return node;
+ }
+ if (items) {
+ return {
+ ...node,
+ items: stripSpoilersFromMarkdownAST(items),
+ };
+ }
+ if (content) {
+ return {
+ ...node,
+ content: stripSpoilersFromMarkdownAST(content),
+ };
+ }
+
+ return node;
+ });
+};
+
export {
paragraphRegex,
paragraphStripTrailingNewlineRegex,
@@ -278,4 +317,5 @@
parseList,
matchMentions,
stripSpoilersFromNotifications,
+ stripSpoilersFromMarkdownAST,
};
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
@@ -20,6 +20,7 @@
type ASTNode,
type SingleASTNode,
stripSpoilersFromNotifications,
+ stripSpoilersFromMarkdownAST,
} from '../markdown';
import { threadIsGroupChat } from '../thread-utils';
import { stringForUser } from '../user-utils';
@@ -89,8 +90,9 @@
messageTitle({ messageInfo, markdownRules }) {
const { text } = messageInfo;
const parser = SimpleMarkdown.parserFor(markdownRules);
- const ast = parser(text, { disableAutoBlockNewlines: true });
-
+ const ast = stripSpoilersFromMarkdownAST(
+ parser(text, { disableAutoBlockNewlines: true }),
+ );
return getFirstNonQuotedRawLine(ast).trim();
},

File Metadata

Mime Type
text/plain
Expires
Wed, Dec 10, 3:00 PM (21 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5864546
Default Alt Text
D5715.1765378832.diff (2 KB)

Event Timeline