Blame Raw
· · · 30 lines (1.1 KB)
0 contributors
1/**
2 * Patches showdown to unrestrictedly unhash HTML spans.
3 * @param {import('showdown')} showdown The showdown object to patch
4 */
5export function addShowdownPatch(showdown) {
6 showdown.subParser('unhashHTMLSpans', function (text, options, globals) {
7 'use strict';
8 text = globals.converter._dispatch('unhashHTMLSpans.before', text, options, globals);
9
10 for (var i = 0; i < globals.gHtmlSpans.length; ++i) {
11 var repText = globals.gHtmlSpans[i],
12 // limiter to prevent infinite loop (assume 10 as limit for recurse)
13 limit = 0;
14
15 while (/¨C(\d+)C/.test(repText)) {
16 var num = RegExp.$1;
17 repText = repText.replace('¨C' + num + 'C', globals.gHtmlSpans[num]);
18 if (limit === 10000) {
19 console.error('maximum nesting of 10000 spans reached!!!');
20 break;
21 }
22 ++limit;
23 }
24 text = text.replace('¨C' + i + 'C', repText);
25 }
26
27 text = globals.converter._dispatch('unhashHTMLSpans.after', text, options, globals);
28 return text;
29 });
30}