mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-13 01:46:57 +01:00
28 lines
758 B
JavaScript
28 lines
758 B
JavaScript
// Showdown extension that replaces words surrounded by singular underscores with <em> tags
|
|
export const markdownUnderscoreExt = () => {
|
|
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;
|
|
}
|
|
}
|