diff options
author | Michael Catanzaro <mcatanzaro@gnome.org> | 2020-09-21 09:13:00 -0500 |
---|---|---|
committer | Michael Catanzaro <mcatanzaro@gnome.org> | 2020-09-21 09:15:08 -0500 |
commit | a348898ff811c61b33e38071f9a03570eedd2aa0 (patch) | |
tree | e64c5a81c472dcc0fd3c868dffaebd71993c60f2 | |
parent | c022e3ac2d13aad5200f43e71e46dd43ba533750 (diff) | |
download | epiphany-mcatanzaro/highlightjs-10.2.1.tar.gz |
Update to highlight.js 10.2.1mcatanzaro/highlightjs-10.2.1
Another day, another highlight.js release.
-rw-r--r-- | third-party/highlightjs/highlight.js | 69 |
1 files changed, 47 insertions, 22 deletions
diff --git a/third-party/highlightjs/highlight.js b/third-party/highlightjs/highlight.js index cb421eea3..08b11e98c 100644 --- a/third-party/highlightjs/highlight.js +++ b/third-party/highlightjs/highlight.js @@ -1,5 +1,5 @@ /* - Highlight.js 10.2.0 (da7d149b) + Highlight.js 10.2.0 (519f7798) License: BSD-3-Clause Copyright (c) 2006-2020, Ivan Sagalaev */ @@ -913,7 +913,7 @@ var hljs = (function () { } resumingScanAtSamePosition() { - return this.regexIndex != 0; + return this.regexIndex !== 0; } considerAll() { @@ -930,15 +930,55 @@ var hljs = (function () { exec(s) { const m = this.getMatcher(this.regexIndex); m.lastIndex = this.lastIndex; - const result = m.exec(s); + let result = m.exec(s); + + // The following is because we have no easy way to say "resume scanning at the + // existing position but also skip the current rule ONLY". What happens is + // all prior rules are also skipped which can result in matching the wrong + // thing. Example of matching "booger": + + // our matcher is [string, "booger", number] + // + // ....booger.... + + // if "booger" is ignored then we'd really need a regex to scan from the + // SAME position for only: [string, number] but ignoring "booger" (if it + // was the first match), a simple resume would scan ahead who knows how + // far looking only for "number", ignoring potential string matches (or + // future "booger" matches that might be valid.) + + // So what we do: We execute two matchers, one resuming at the same + // position, but the second full matcher starting at the position after: + + // /--- resume first regex match here (for [number]) + // |/---- full match here for [string, "booger", number] + // vv + // ....booger.... + + // Which ever results in a match first is then used. So this 3-4 step + // process essentially allows us to say "match at this position, excluding + // a prior rule that was ignored". + // + // 1. Match "booger" first, ignore. Also proves that [string] does non match. + // 2. Resume matching for [number] + // 3. Match at index + 1 for [string, "booger", number] + // 4. If #2 and #3 result in matches, which came first? + if (this.resumingScanAtSamePosition()) { + if (result && result.index === this.lastIndex) ; else { // use the second matcher result + const m2 = this.getMatcher(0); + m2.lastIndex = this.lastIndex + 1; + result = m2.exec(s); + } + } + if (result) { this.regexIndex += result.position + 1; - if (this.regexIndex === this.count) { // wrap-around - this.regexIndex = 0; + if (this.regexIndex === this.count) { + // wrap-around to considering all matches again + this.considerAll(); } } - // this.regexIndex = 0; return result; } } @@ -1542,14 +1582,6 @@ var hljs = (function () { } /** - * Advance a single character - */ - function advanceOne() { - mode_buffer += codeToHighlight[index]; - index += 1; - } - - /** * Handle matching but then ignoring a sequence of text * * @param {string} lexeme - string containing full match text @@ -1778,20 +1810,13 @@ var hljs = (function () { // considered for a potential match resumeScanAtSamePosition = false; } else { - top.matcher.lastIndex = index; top.matcher.considerAll(); } + top.matcher.lastIndex = index; const match = top.matcher.exec(codeToHighlight); // console.log("match", match[0], match.rule && match.rule.begin) - // if our failure to match was the result of a "resumed scan" then we - // need to advance one position and revert to full scanning before we - // decide there are truly no more matches at all to be had - if (!match && top.matcher.resumingScanAtSamePosition()) { - advanceOne(); - continue; - } if (!match) break; const beforeMatch = codeToHighlight.substring(index, match.index); |