Message Input: Fix markdown parsing inside code and links (#1579)

This commit is contained in:
Alexander Zinchuk 2021-12-13 15:36:50 +01:00
parent dd4fcfd500
commit eb05b49dd6

View File

@ -84,9 +84,18 @@ function parseMarkdown(html: string) {
parsedHtml = parsedHtml.replace(/[`]{1}([^`\n]+)[`]{1}/g, '<code>$1</code>');
// Other simple markdown
parsedHtml = parsedHtml.replace(/[*]{2}([^*\n]+)[*]{2}/g, '<b>$1</b>');
parsedHtml = parsedHtml.replace(/[_]{2}([^*\n]+)[_]{2}/g, '<i>$1</i>');
parsedHtml = parsedHtml.replace(/[~]{2}([^~\n]+)[~]{2}/g, '<s>$1</s>');
parsedHtml = parsedHtml.replace(
/(\s)(?<!<code[^<]*|<\/)[*]{2}([^*\n]+)[*]{2}(?![^<]*<\/code>)(\s|$)/g,
'$1<b>$2</b>$3',
);
parsedHtml = parsedHtml.replace(
/(\s)(?<!<code[^<]*|<\/)[_]{2}([^_\n]+)[_]{2}(?![^<]*<\/code>)(\s|$)/g,
'$1<i>$2</i>$3',
);
parsedHtml = parsedHtml.replace(
/(\s)(?<!<code[^<]*|<\/)[~]{2}([^~\n]+)[~]{2}(?![^<]*<\/code>)(\s|$)/g,
'$1<s>$2</s>$3',
);
return parsedHtml;
}