SillyTavern/public/scripts/showdown-underscore.js

23 lines
582 B
JavaScript
Raw Normal View History

// Showdown extension that replaces words surrounded by singular underscores with <em> tags
export const markdownUnderscoreExt = () => {
if (!canUseNegativeLookbehind()) {
console.log('Showdown-underscore extension: Negative lookbehind not supported. Skipping.');
return [];
}
return [{
type: 'lang',
regex: /\b(?<!_)_(?!_)(.*?)(?<!_)_(?!_)\b/g,
replace: '<em>$1</em>',
}];
};
function canUseNegativeLookbehind() {
try {
new RegExp('(?<!_)');
return true;
} catch (e) {
return false;
}
}