The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/server/services/messages/hooks/BeforeSaveMarkdownParser.ts

43 lines
1002 B

import { isE2EEMessage } from '@rocket.chat/core-typings';
import type { IMessage } from '@rocket.chat/core-typings';
import { parse } from '@rocket.chat/message-parser';
type ParserConfig = {
colors?: boolean;
emoticons?: boolean;
customDomains?: string[];
katex?: {
dollarSyntax: boolean;
parenthesisSyntax: boolean;
};
};
export class BeforeSaveMarkdownParser {
constructor(private enabled: boolean = true) {
// no op
}
async parseMarkdown({ message, config }: { message: IMessage; config: ParserConfig }): Promise<IMessage> {
if (!this.enabled) {
return message;
}
if (isE2EEMessage(message)) {
return message;
}
try {
if (message.msg) {
message.md = parse(message.msg, config);
}
if (message.attachments?.[0]?.description) {
message.attachments[0].descriptionMd = parse(message.attachments[0].description, config);
}
} catch (e) {
console.error(e); // errors logged while the parser is at experimental stage
}
return message;
}
}