Don't replace underscore italics inside of code blocks

This commit is contained in:
Cohee 2024-08-18 13:58:47 +03:00
parent 9215dfd0c6
commit c0c09f9a5d

View File

@ -8,8 +8,16 @@ export const markdownUnderscoreExt = () => {
return [{
type: 'lang',
regex: new RegExp('\\b(?<!_)_(?!_)(.*?)(?<!_)_(?!_)\\b', 'g'),
replace: '<em>$1</em>',
regex: new RegExp('(`{1,3}).*?\\1|\\b(?<!_)_(?!_)(.*?)(?<!_)_(?!_)\\b', 'gs'),
replace: function(match, codeBlock, italicContent) {
if (codeBlock) {
// If it's a code block, return it unchanged
return match;
} else {
// If it's an italic group, apply the replacement
return `<em>${italicContent}</em>`;
}
},
}];
} catch (e) {
console.error('Error in Showdown-underscore extension:', e);