2024-03-03 14:26:25 +01:00
|
|
|
// 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);
|
2024-03-03 14:26:25 +01:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function canUseNegativeLookbehind() {
|
|
|
|
try {
|
|
|
|
new RegExp('(?<!_)');
|
|
|
|
return true;
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|