Fix for unmatched single backticks

This commit is contained in:
Cohee 2024-08-18 14:15:22 +03:00
parent c0c09f9a5d
commit e137c5d154
1 changed files with 8 additions and 6 deletions

View File

@ -8,15 +8,17 @@ export const markdownUnderscoreExt = () => {
return [{ return [{
type: 'lang', type: 'lang',
regex: new RegExp('(`{1,3}).*?\\1|\\b(?<!_)_(?!_)(.*?)(?<!_)_(?!_)\\b', 'gs'), regex: new RegExp('(`{3})[\\s\\S]*?\\1|(`{1,2}).*?\\2|\\b(?<!_)_(?!_)(.*?)(?<!_)_(?!_)\\b', 'g'),
replace: function(match, codeBlock, italicContent) { replace: function(match, tripleBackticks, singleOrDoubleBackticks, italicContent) {
if (codeBlock) { if (tripleBackticks || singleOrDoubleBackticks) {
// If it's a code block, return it unchanged // If it's any kind of code block, return it unchanged
return match; return match;
} else { } else if (italicContent) {
// If it's an italic group, apply the replacement // If it's an italic group, apply the replacement
return `<em>${italicContent}</em>`; return '<em>' + italicContent + '</em>';
} }
// If neither condition is met, return the original match
return match;
}, },
}]; }];
} catch (e) { } catch (e) {