Don't replace underscore italics inside of code blocks

c0c09f9a5d82cfc6ebc72f9b0af10f69a5ab10e7

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +10 -2Showing whitespace changes
public/scripts/showdown-underscore.js+10 -2
@@ -8,8 +8,16 @@ export const markdownUnderscoreExt = () => {
88
99 return [{
1010 type: 'lang',
1111 regex: new RegExp('(`{1,3}).*?\\1|\\b(?<!_)_(?!_)(.*?)(?<!_)_(?!_)\\b', 'ggs'),
12- replace: '<em>$1</em>',
12+ replace: function(match, codeBlock, italicContent) {
13+ if (codeBlock) {
14+ // If it's a code block, return it unchanged
15+ return match;
16+ } else {
17+ // If it's an italic group, apply the replacement
18+ return `<em>${italicContent}</em>`;
19+ }
20+ },
1321 }];
1422 } catch (e) {
1523 console.error('Error in Showdown-underscore extension:', e);