Showdown: parse single underscores as italics

This commit is contained in:
Cohee
2024-03-03 15:26:25 +02:00
parent be38359d66
commit 39c588f30e
2 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,22 @@
// 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;
}
}