2015-01-16 05:21:33 +08:00
|
|
|
/**
|
|
|
|
* Smart processing for ampersands and angle brackets that need to be encoded.
|
|
|
|
*/
|
2017-01-30 03:28:30 +08:00
|
|
|
showdown.subParser('encodeAmpsAndAngles', function (text, options, globals) {
|
2015-01-19 19:37:21 +08:00
|
|
|
'use strict';
|
2017-01-30 03:28:30 +08:00
|
|
|
text = globals.converter._dispatch('encodeAmpsAndAngles.before', text, options, globals);
|
|
|
|
|
2015-01-19 19:37:21 +08:00
|
|
|
// 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, '&');
|
2015-01-16 05:21:33 +08:00
|
|
|
|
2015-01-19 19:37:21 +08:00
|
|
|
// Encode naked <'s
|
|
|
|
text = text.replace(/<(?![a-z\/?\$!])/gi, '<');
|
2015-01-16 05:21:33 +08:00
|
|
|
|
2017-01-30 03:28:30 +08:00
|
|
|
text = globals.converter._dispatch('encodeAmpsAndAngles.after', text, options, globals);
|
2015-01-19 19:37:21 +08:00
|
|
|
return text;
|
2015-01-16 05:21:33 +08:00
|
|
|
});
|