Markdown: Fix custom emoji parsing (#2364)
This commit is contained in:
parent
84bfe0c8fc
commit
7902cda648
@ -1,6 +1,7 @@
|
|||||||
import type { ApiMessageEntity, ApiFormattedText } from '../api/types';
|
import type { ApiMessageEntity, ApiFormattedText } from '../api/types';
|
||||||
import { ApiMessageEntityTypes } from '../api/types';
|
import { ApiMessageEntityTypes } from '../api/types';
|
||||||
import { RE_LINK_TEMPLATE } from '../config';
|
import { RE_LINK_TEMPLATE } from '../config';
|
||||||
|
import { IS_EMOJI_SUPPORTED } from './environment';
|
||||||
|
|
||||||
export const ENTITY_CLASS_BY_NODE_NAME: Record<string, ApiMessageEntityTypes> = {
|
export const ENTITY_CLASS_BY_NODE_NAME: Record<string, ApiMessageEntityTypes> = {
|
||||||
B: ApiMessageEntityTypes.Bold,
|
B: ApiMessageEntityTypes.Bold,
|
||||||
@ -101,9 +102,13 @@ function parseMarkdown(html: string) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Custom Emoji markdown tag
|
// Custom Emoji markdown tag
|
||||||
|
if (!IS_EMOJI_SUPPORTED) {
|
||||||
|
// Prepare alt text for custom emoji
|
||||||
|
parsedHtml = parsedHtml.replace(/\[<img[^>]+alt="([^"]+)"[^>]*>]/gm, '[$1]');
|
||||||
|
}
|
||||||
parsedHtml = parsedHtml.replace(
|
parsedHtml = parsedHtml.replace(
|
||||||
/(^|\s)(?!<(?:code|pre)[^<]*|<\/)\[([^\]\n]+)\]\(customEmoji:(\d+)\)(?![^<]*<\/(?:code|pre)>)(\s|$)/g,
|
/(?!<(?:code|pre)[^<]*|<\/)\[([^\]\n]+)\]\(customEmoji:(\d+)\)(?![^<]*<\/(?:code|pre)>)/g,
|
||||||
'$1<img alt="$2" data-document-id="$3">$4',
|
'<img alt="$1" data-document-id="$2">',
|
||||||
);
|
);
|
||||||
|
|
||||||
// Other simple markdown
|
// Other simple markdown
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user