showdown/src/subParsers/hashHTMLSpans.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

32 lines
1.0 KiB
JavaScript

/**
* Hash span elements that should not be parsed as markdown
*/
showdown.subParser('hashHTMLSpans', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('hashHTMLSpans.before', text, options, globals);
var matches = showdown.helper.matchRecursiveRegExp(text, '<code\\b[^>]*>', '</code>', 'gi');
for (var i = 0; i < matches.length; ++i) {
text = text.replace(matches[i][0], '¨C' + (globals.gHtmlSpans.push(matches[i][0]) - 1) + 'C');
}
text = globals.converter._dispatch('hashHTMLSpans.after', text, options, globals);
return text;
});
/**
* Unhash HTML spans
*/
showdown.subParser('unhashHTMLSpans', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('unhashHTMLSpans.before', text, options, globals);
for (var i = 0; i < globals.gHtmlSpans.length; ++i) {
text = text.replace('¨C' + i + 'C', globals.gHtmlSpans[i]);
}
text = globals.converter._dispatch('unhashHTMLSpans.after', text, options, globals);
return text;
});