Skip to content

Commit

Permalink
(fix) fix illegal handling at end of input code
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Dec 27, 2024
1 parent 08cb242 commit 62f8a60
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,18 @@ const HLJS = function(hljs) {
}
}

// edge case for when illegal matches $ (end of line) which is technically
// edge case for when illegal matches $ (end of line/text) which is technically
// a 0 width match but not a begin/end match so it's not caught by the
// first handler (when ignoreIllegals is true)
// first handler (when `ignoreIllegals` is true)
if (match.type === "illegal" && lexeme === "") {
// advance so we aren't stuck in an infinite loop
modeBuffer += "\n";
if (match.index === codeToHighlight.length) {
// we have matched the end of the text, so we can stop without
// hacking modeBuffer
} else {
// matched literal `\n` (with `$`) so we must manually add the newline
// itself to the modeBuffer so it is not lost when we advance the cursor
modeBuffer += "\n";
}
return 1;
}

Expand Down

0 comments on commit 62f8a60

Please sign in to comment.