Last active
September 14, 2018 21:49
-
-
Save tivie/7f8a88c89ffb00d2afe6c59a25528386 to your computer and use it in GitHub Desktop.
Showdownjs replacement for literalMidWordAsterisks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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