Skip to content

Commit

Permalink
improve RegExp usage in converter
Browse files Browse the repository at this point in the history
  • Loading branch information
balpha committed Aug 25, 2011
1 parent 8c11b15 commit d823948
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Markdown.Converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,8 @@ else

var grafs = text.split(/\n{2,}/g);
var grafsOut = [];

var markerRe = /~K(\d+)K/g;

//
// Wrap <p> tags.
Expand All @@ -1122,10 +1124,10 @@ else
var str = grafs[i];

// if this is an HTML marker, copy it
if (str.search(/~K(\d+)K/g) >= 0) {
if (markerRe.test(str)) {
grafsOut.push(str);
}
else if (str.search(/\S/) >= 0) {
else if (/\S/.test(str)) {
str = _RunSpanGamut(str);
str = str.replace(/^([ \t]*)/g, "<p>");
str += "</p>"
Expand All @@ -1139,11 +1141,13 @@ else
if (!doNotUnhash) {
end = grafsOut.length;
for (var i = 0; i < end; i++) {
// if this is a marker for an html block...
while (grafsOut[i].search(/~K(\d+)K/) >= 0) {
var blockText = g_html_blocks[RegExp.$1];
blockText = blockText.replace(/\$/g, "$$$$"); // Escape any dollar signs
grafsOut[i] = grafsOut[i].replace(/~K\d+K/, blockText);
var foundAny = true;
while (foundAny) { // we may need several runs, since the data may be nested
foundAny = false;
grafsOut[i] = grafsOut[i].replace(markerRe, function (wholeMatch, id) {
foundAny = true;
return g_html_blocks[id];
});
}
}
}
Expand Down

0 comments on commit d823948

Please sign in to comment.