src/subParsers/makehtml/encodeAmpsAndAngles.js
/**
* Smart processing for ampersands and angle brackets that need to be encoded.
*/
showdown.subParser('makehtml.encodeAmpsAndAngles', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('makehtml.encodeAmpsAndAngles.before', text, options, globals).getText();
// 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, '<');
// Encode <
text = text.replace(/</g, '<');
// Encode >
text = text.replace(/>/g, '>');
text = globals.converter._dispatch('makehtml.encodeAmpsAndAngles.after', text, options, globals).getText();
return text;
});