SillyTavern/public/scripts/showdown-underscore.js

28 lines
758 B
JavaScript
Raw Normal View History

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