showdown/src/subParsers/encodeAmpsAndAngles.js
Estevao Soares dos Santos 7d63a3e635 feat(events): add events to all subparsers
This commit adds events to all subparsers (that were previously not being watched).
2017-01-29 19:28:30 +00:00

18 lines
649 B
JavaScript

/**
* Smart processing for ampersands and angle brackets that need to be encoded.
*/
showdown.subParser('encodeAmpsAndAngles', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('encodeAmpsAndAngles.before', text, options, globals);
// Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
// http://bumppo.net/projects/amputator/
text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g, '&');
// Encode naked <'s
text = text.replace(/<(?![a-z\/?\$!])/gi, '&lt;');
text = globals.converter._dispatch('encodeAmpsAndAngles.after', text, options, globals);
return text;
});