Skip to content

Instantly share code, notes, and snippets.

@tivie
Last active September 14, 2018 21:49
Show Gist options
  • Save tivie/7f8a88c89ffb00d2afe6c59a25528386 to your computer and use it in GitHub Desktop.
Save tivie/7f8a88c89ffb00d2afe6c59a25528386 to your computer and use it in GitHub Desktop.
Showdownjs replacement for literalMidWordAsterisks
showdown.extension('literalMidWordAsterisks', function () {
return [{
type: 'listener',
listeners: {
'italicsAndBold.before': function (event, text, options, globals) {
if (options.literalMidWordAsterisks) {
text = text.replace(/\b\*{1,}\b/g, function (wm) {
return wm.split('').map(function () { return '¨A';}).join('');
})
}
return text;
},
'italicsAndBold.after': function (event, text, options, globals) {
return text.replace('¨A', '*');
},
}
}];
});
// to run the extension
var conv = new showdown.Converter({
extensions: ['literalMidWordAsterisks'],
literalMidWordAsterisks: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment