Merge pull request #2679 from SillyTavern/codeblock-underscores Don't replace underscore italics inside of code blocks

44e62156b7cfd5ed2d23673f341ae90cc142fa45

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

Signed
1 files changed, +13 -3Ignore whitespace
public/scripts/showdown-underscore.js+13 -3
@@ -7,9 +7,19 @@ export const markdownUnderscoreExt = () => {
7 }7 }
88
9 return [{9 return [{
10 type: 'lang',10 type: 'output',
11 regex: new RegExp('\\b(?<!_)_(?!_)(.*?)(?<!_)_(?!_)\\b', 'g'),11 regex: new RegExp('(<code>[\\s\\S]*?<\\/code>)|(?<!\\S)_(?!_)([^_\\n]+?)(?<!_)_(?!\\w)', 'g'),
12 replace: '<em>$1</em>',12 replace: function(match, codeContent, italicContent) {
13 if (codeContent) {
14 // If it's inside <code> tags, return unchanged
15 return match;
16 } else if (italicContent) {
17 // If it's an italic group, apply the replacement
18 return '<em>' + italicContent + '</em>';
19 }
20 // If none of the conditions are met, return the original match
21 return match;
22 },
13 }];23 }];
14 } catch (e) {24 } catch (e) {
15 console.error('Error in Showdown-underscore extension:', e);25 console.error('Error in Showdown-underscore extension:', e);