@@ -261,6 +261,14 @@ const HLJS = function(hljs) {
261
261
}
262
262
}
263
263
264
+ /**
265
+ * Advance a single character
266
+ */
267
+ function advanceOne ( ) {
268
+ mode_buffer += codeToHighlight [ index ] ;
269
+ index += 1 ;
270
+ }
271
+
264
272
/**
265
273
* Handle matching but then ignoring a sequence of text
266
274
*
@@ -275,7 +283,7 @@ const HLJS = function(hljs) {
275
283
} else {
276
284
// no need to move the cursor, we still have additional regexes to try and
277
285
// match at this very spot
278
- continueScanAtSamePosition = true ;
286
+ resumeScanAtSamePosition = true ;
279
287
return 0 ;
280
288
}
281
289
}
@@ -478,23 +486,32 @@ const HLJS = function(hljs) {
478
486
var relevance = 0 ;
479
487
var index = 0 ;
480
488
var iterations = 0 ;
481
- var continueScanAtSamePosition = false ;
489
+ var resumeScanAtSamePosition = false ;
482
490
483
491
try {
484
492
top . matcher . considerAll ( ) ;
485
493
486
494
for ( ; ; ) {
487
495
iterations ++ ;
488
- if ( continueScanAtSamePosition ) {
496
+ if ( resumeScanAtSamePosition ) {
489
497
// only regexes not matched previously will now be
490
498
// considered for a potential match
491
- continueScanAtSamePosition = false ;
499
+ resumeScanAtSamePosition = false ;
492
500
} else {
493
501
top . matcher . lastIndex = index ;
494
502
top . matcher . considerAll ( ) ;
495
503
}
504
+
496
505
const match = top . matcher . exec ( codeToHighlight ) ;
497
506
// console.log("match", match[0], match.rule && match.rule.begin)
507
+
508
+ // if our failure to match was the result of a "resumed scan" then we
509
+ // need to advance one position and revert to full scanning before we
510
+ // decide there are truly no more matches at all to be had
511
+ if ( ! match && top . matcher . resumingScanAtSamePosition ( ) ) {
512
+ advanceOne ( ) ;
513
+ continue ;
514
+ }
498
515
if ( ! match ) break ;
499
516
500
517
const beforeMatch = codeToHighlight . substring ( index , match . index ) ;
0 commit comments