mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #2679 from SillyTavern/codeblock-underscores
Don't replace underscore italics inside of code blocks
This commit is contained in:
@ -7,9 +7,19 @@ export const markdownUnderscoreExt = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [{
|
return [{
|
||||||
type: 'lang',
|
type: 'output',
|
||||||
regex: new RegExp('\\b(?<!_)_(?!_)(.*?)(?<!_)_(?!_)\\b', 'g'),
|
regex: new RegExp('(<code>[\\s\\S]*?<\\/code>)|(?<!\\S)_(?!_)([^_\\n]+?)(?<!_)_(?!\\w)', 'g'),
|
||||||
replace: '<em>$1</em>',
|
replace: function(match, codeContent, italicContent) {
|
||||||
|
if (codeContent) {
|
||||||
|
// If it's inside <code> tags, return unchanged
|
||||||
|
return match;
|
||||||
|
} else if (italicContent) {
|
||||||
|
// If it's an italic group, apply the replacement
|
||||||
|
return '<em>' + italicContent + '</em>';
|
||||||
|
}
|
||||||
|
// If none of the conditions are met, return the original match
|
||||||
|
return match;
|
||||||
|
},
|
||||||
}];
|
}];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error in Showdown-underscore extension:', e);
|
console.error('Error in Showdown-underscore extension:', e);
|
||||||
|
Reference in New Issue
Block a user