I'm just having fun with Showdown extensions, exploring how I could interfere with Showdown's work to beautify Markdown while it is being parsed.
Here are some examples of objectives:
- Replace
<space>?
with<nbsp;>?
(in French, a question mark is preceeded with a space, but you don't want the line to break).Eg
Showdown est super !
would be converted asShowdown est super !
- Add thousand separators in numbers.
Eg
1234567
would be converted as1,234,567
(or narrow no-break space as thousand separator in French).
Of course we want to do that only in text. We don't want to alter citations or hyperlinks.
The first example is easy to implement, this is already done in MemCheck, and it works. But this is ugly code, inefficient, not smart. And, more importantly, this can't be done for numbers, otherwise we will break URLs.
function beautifyTextForFrench(src) {
var result = src.replace(/\s\?/g, " ?");
result = result.replace(/\s!/g, " !");
result = result.replace(/\s;/g, " ;");
result = result.replace(/\s:/g, " :");
return result;
}
I hope that a future version of Showdown will bring very cool new features related to these needs (see this issue).
The file of interest is index.js. You probably don't want to compile the project; but in case you want to, just open the sln file with Visual Studio (I use version 2022).