Skip to content

Commit e8852a8

Browse files
committed
refactor: clean regex helper functions
1 parent c97f1dc commit e8852a8

5 files changed

Lines changed: 25 additions & 57 deletions

File tree

dist/showdown.js

Lines changed: 11 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/helpers.js

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -187,35 +187,19 @@ var rgxFindMatchPos = function (str, left, right, flags) {
187187
*/
188188
showdown.helper.matchRecursiveRegExp = function (str, left, right, flags) {
189189
'use strict';
190-
var f = flags || '',
191-
g = f.indexOf('g') > -1,
192-
x = new RegExp(left + '|' + right, 'g' + f.replace(/g/g, '')),
193-
l = new RegExp(left, f.replace(/g/g, '')),
194-
a = [],
195-
t, s, m, start, end;
196190

197-
do {
198-
t = 0;
199-
while ((m = x.exec(str))) {
200-
if (l.test(m[0])) {
201-
if (!(t++)) {
202-
start = m[0];
203-
s = x.lastIndex;
204-
}
205-
} else if (t) {
206-
if (!--t) {
207-
end = m[0];
208-
var match = str.slice(s, m.index);
209-
a.push([start + match + end, match, start, end]);
210-
if (!g) {
211-
return a;
212-
}
213-
}
214-
}
215-
}
216-
} while (t && (x.lastIndex = s));
191+
var matchPos = rgxFindMatchPos (str, left, right, flags),
192+
results = [];
217193

218-
return a;
194+
for (var i = 0; i < matchPos.length; ++i) {
195+
results.push([
196+
str.slice(matchPos[i].wholeMatch.start, matchPos[i].wholeMatch.end),
197+
str.slice(matchPos[i].match.start, matchPos[i].match.end),
198+
str.slice(matchPos[i].left.start, matchPos[i].left.end),
199+
str.slice(matchPos[i].right.start, matchPos[i].right.end)
200+
]);
201+
}
202+
return results;
219203
};
220204

221205
/**

0 commit comments

Comments
 (0)