Skip to content

Commit

Permalink
DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Feb 28, 2020
1 parent 295cdd5 commit 013ccff
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/highlight.js
Expand Up @@ -177,7 +177,6 @@ const HLJS = function(hljs) {
function startNewMode(mode) {
result += mode.className? buildSpan(mode.className, '', true): '';
top = Object.create(mode, {parent: {value: top}});
top.terminators.startAt = 0;
}

function doIgnore(lexeme) {
Expand All @@ -189,6 +188,7 @@ const HLJS = function(hljs) {
} else {
// no need to move the cursor, we still have additional regexes to try and
// match at this very spot
findNextRegexMatch = true;
return 0;
}
}
Expand All @@ -203,9 +203,6 @@ const HLJS = function(hljs) {
return doIgnore(lexeme);
}

// we are not ignoring, so next match should start with first regex in stack
top.terminators.startAt = 0;

if (new_mode && new_mode.endSameAsBegin) {
new_mode.endRe = regex.escape( lexeme );
}
Expand All @@ -229,7 +226,6 @@ const HLJS = function(hljs) {
var lexeme = match[0];
var matchPlusRemainder = codeToHighlight.substr(match.index);
var end_mode = endOfMode(top, matchPlusRemainder);
top.terminators.startAt = 0;
if (!end_mode) { return; }

var origin = top;
Expand Down Expand Up @@ -282,7 +278,6 @@ const HLJS = function(hljs) {
// sometimes they can end up matching nothing at all
// Ref: https://github.com/highlightjs/highlight.js/issues/2140
if (lastMatch.type=="begin" && match.type=="end" && lastMatch.index == match.index && lexeme === "") {
top.terminators.startAt = 0;
// spit the "skipped" character that our regex choked on back into the output sequence
mode_buffer += codeToHighlight.slice(match.index, match.index + 1);
if (!SAFE_MODE) {
Expand Down Expand Up @@ -339,11 +334,17 @@ const HLJS = function(hljs) {
}
var mode_buffer = '';
var relevance = 0;
var findNextRegexMatch = false;
try {
var match, count, index = 0;
top.terminators.startAt = 0;

while (true) {
top.terminators.lastIndex = index;
if (findNextRegexMatch) {
findNextRegexMatch = false;
} else {
top.terminators.startAt = 0;
}
match = top.terminators.exec(codeToHighlight);
// console.log("match", match[0], match.rule && match.rule.begin)
if (!match)
Expand Down

0 comments on commit 013ccff

Please sign in to comment.