Skip to content

Commit

Permalink
refactor: clean regex helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tivie committed Jan 2, 2016
1 parent c97f1dc commit e8852a8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 57 deletions.
38 changes: 11 additions & 27 deletions dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

38 changes: 11 additions & 27 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,35 +187,19 @@ var rgxFindMatchPos = function (str, left, right, flags) {
*/
showdown.helper.matchRecursiveRegExp = function (str, left, right, flags) {
'use strict';
var f = flags || '',
g = f.indexOf('g') > -1,
x = new RegExp(left + '|' + right, 'g' + f.replace(/g/g, '')),
l = new RegExp(left, f.replace(/g/g, '')),
a = [],
t, s, m, start, end;

do {
t = 0;
while ((m = x.exec(str))) {
if (l.test(m[0])) {
if (!(t++)) {
start = m[0];
s = x.lastIndex;
}
} else if (t) {
if (!--t) {
end = m[0];
var match = str.slice(s, m.index);
a.push([start + match + end, match, start, end]);
if (!g) {
return a;
}
}
}
}
} while (t && (x.lastIndex = s));
var matchPos = rgxFindMatchPos (str, left, right, flags),
results = [];

return a;
for (var i = 0; i < matchPos.length; ++i) {
results.push([
str.slice(matchPos[i].wholeMatch.start, matchPos[i].wholeMatch.end),
str.slice(matchPos[i].match.start, matchPos[i].match.end),
str.slice(matchPos[i].left.start, matchPos[i].left.end),
str.slice(matchPos[i].right.start, matchPos[i].right.end)
]);
}
return results;
};

/**
Expand Down

0 comments on commit e8852a8

Please sign in to comment.