diff --git a/src/highlight.js b/src/highlight.js index 7adb239a86..ddc1eba27e 100644 --- a/src/highlight.js +++ b/src/highlight.js @@ -707,6 +707,16 @@ https://highlightjs.org/ mode_buffer += codeToHighlight.slice(match.index, match.index + 1); return 1; } + + // edge case for when illegal matches $ (end of line) 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) + // https://github.com/highlightjs/highlight.js/issues/2522 + if (lastMatch.type==="illegal" && lexeme === "") { + mode_buffer += codeToHighlight.slice(match.index, match.index + 1); + return 1; + } + lastMatch = match; if (match.type==="begin") {