Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/subParsers/makehtml/hashHTMLSpans.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ showdown.subParser('makehtml.unhashHTMLSpans', function (text, options, globals)
'use strict';
text = globals.converter._dispatch('makehtml.unhashHTMLSpans.before', text, options, globals).getText();

var replacedSpans = [];

for (var i = 0; i < globals.gHtmlSpans.length; ++i) {
var repText = globals.gHtmlSpans[i],
// limiter to prevent infinite loop (assume 10 as limit for recurse)
Expand All @@ -50,9 +52,17 @@ showdown.subParser('makehtml.unhashHTMLSpans', function (text, options, globals)
}
++limit;
}
text = text.replace('¨C' + i + 'C', repText);

replacedSpans.push(repText);
}

// It is important to only do one replace for all the spans combined.
// Otherwise this gets really slow on large texts with many spans because
// of all the string copies.
text = text.replace(/¨C(\d+)C/g, function (_wm, num) {
return replacedSpans[num];
});

text = globals.converter._dispatch('makehtml.unhashHTMLSpans.after', text, options, globals).getText();
return text;
});
Loading