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