File tree Expand file tree Collapse file tree 2 files changed +50
-11
lines changed Expand file tree Collapse file tree 2 files changed +50
-11
lines changed Original file line number Diff line number Diff line change @@ -296,3 +296,32 @@ The value of the attribute controls which language or languages will be used for
296
296
* language name: explicit highlighting with the specified language
297
297
* empty array: auto detection with all the languages available
298
298
* array of language names: auto detection constrained to the specified set
299
+
300
+ skip
301
+ ^^^^
302
+
303
+ **type **: boolean
304
+
305
+ Skips any markup processing for the mode ensuring that it remains a part of its
306
+ parent buffer along with the starting and the ending lexemes. This works in
307
+ conjunction with the parent's :ref: `subLanguage ` when it requires complex
308
+ parsing.
309
+
310
+ Consider parsing JSX inside JavaScript::
311
+
312
+ var x = <node> text <child/> text </node>;
313
+
314
+ You have to correctly balance opening and ending angle brackets to make sure
315
+ that the entire XML node is parsed out before it can be highlighted with a
316
+ sub-language::
317
+
318
+ {
319
+ begin: /</, end: />/,
320
+ subLanguague: 'xml',
321
+ contains: [
322
+ {begin: /</, end: />/, skip: true, contains: ['self']}
323
+ ]
324
+ }
325
+
326
+ Without ``skip: true `` every angle bracket within the root node would cause the
327
+ parser to drop out back into JavaScript.
Original file line number Diff line number Diff line change @@ -393,12 +393,16 @@ https://highlightjs.org/
393
393
394
394
var new_mode = subMode ( lexeme , top ) ;
395
395
if ( new_mode ) {
396
- if ( new_mode . excludeBegin ) {
396
+ if ( new_mode . skip ) {
397
397
mode_buffer += lexeme ;
398
- }
399
- processBuffer ( ) ;
400
- if ( ! new_mode . returnBegin && ! new_mode . excludeBegin ) {
401
- mode_buffer = lexeme ;
398
+ } else {
399
+ if ( new_mode . excludeBegin ) {
400
+ mode_buffer += lexeme ;
401
+ }
402
+ processBuffer ( ) ;
403
+ if ( ! new_mode . returnBegin && ! new_mode . excludeBegin ) {
404
+ mode_buffer = lexeme ;
405
+ }
402
406
}
403
407
startNewMode ( new_mode , lexeme ) ;
404
408
return new_mode . returnBegin ? 0 : lexeme . length ;
@@ -407,18 +411,24 @@ https://highlightjs.org/
407
411
var end_mode = endOfMode ( top , lexeme ) ;
408
412
if ( end_mode ) {
409
413
var origin = top ;
410
- if ( ! ( origin . returnEnd || origin . excludeEnd ) ) {
414
+ if ( origin . skip ) {
411
415
mode_buffer += lexeme ;
412
- }
413
- processBuffer ( ) ;
414
- if ( origin . excludeEnd ) {
415
- mode_buffer = lexeme ;
416
+ } else {
417
+ if ( ! ( origin . returnEnd || origin . excludeEnd ) ) {
418
+ mode_buffer += lexeme ;
419
+ }
420
+ processBuffer ( ) ;
421
+ if ( origin . excludeEnd ) {
422
+ mode_buffer = lexeme ;
423
+ }
416
424
}
417
425
do {
418
426
if ( top . className ) {
419
427
result += '</span>' ;
420
428
}
421
- relevance += top . relevance ;
429
+ if ( ! top . skip ) {
430
+ relevance += top . relevance ;
431
+ }
422
432
top = top . parent ;
423
433
} while ( top != end_mode . parent ) ;
424
434
if ( end_mode . starts ) {
You can’t perform that action at this time.
0 commit comments