@@ -103,8 +103,10 @@ function generateOutput(stack, token, data, options) {
103
103
result = pushText ( data , options ) ;
104
104
} else if ( token === 'display' ) {
105
105
result = handleDisplay ( stack , data , options ) ;
106
- } else if ( token === 'xterm256 ' ) {
106
+ } else if ( token === 'xterm256Foreground ' ) {
107
107
result = pushForegroundColor ( stack , options . colors [ data ] ) ;
108
+ } else if ( token === 'xterm256Background' ) {
109
+ result = pushBackgroundColor ( stack , options . colors [ data ] ) ;
108
110
} else if ( token === 'rgb' ) {
109
111
result = handleRgb ( stack , data ) ;
110
112
}
@@ -119,10 +121,10 @@ function generateOutput(stack, token, data, options) {
119
121
*/
120
122
function handleRgb ( stack , data ) {
121
123
data = data . substring ( 2 ) . slice ( 0 , - 1 ) ;
122
- const operation = + data . substr ( 0 , 2 ) ;
124
+ const operation = + data . substr ( 0 , 2 ) ;
123
125
124
126
const color = data . substring ( 5 ) . split ( ';' ) ;
125
- const rgb = color . map ( function ( value ) {
127
+ const rgb = color . map ( function ( value ) {
126
128
return ( '0' + Number ( value ) . toString ( 16 ) ) . substr ( - 2 ) ;
127
129
} ) . join ( '' ) ;
128
130
@@ -280,7 +282,7 @@ function pushTag(stack, tag, style) {
280
282
* @param {string } style
281
283
* @returns {string }
282
284
*/
283
- function pushStyle ( stack , style ) {
285
+ function pushStyle ( stack , style ) {
284
286
return pushTag ( stack , 'span' , style ) ;
285
287
}
286
288
@@ -323,8 +325,13 @@ function tokenize(text, options, callback) {
323
325
return '' ;
324
326
}
325
327
326
- function removeXterm256 ( m , g1 ) {
327
- callback ( 'xterm256' , g1 ) ;
328
+ function removeXterm256Foreground ( m , g1 ) {
329
+ callback ( 'xterm256Foreground' , g1 ) ;
330
+ return '' ;
331
+ }
332
+
333
+ function removeXterm256Background ( m , g1 ) {
334
+ callback ( 'xterm256Background' , g1 ) ;
328
335
return '' ;
329
336
}
330
337
@@ -380,11 +387,14 @@ function tokenize(text, options, callback) {
380
387
sub : rgb
381
388
} , {
382
389
pattern : / ^ \x1b \[ 3 8 ; 5 ; ( \d + ) m / ,
383
- sub : removeXterm256
390
+ sub : removeXterm256Foreground
391
+ } , {
392
+ pattern : / ^ \x1b \[ 4 8 ; 5 ; ( \d + ) m / ,
393
+ sub : removeXterm256Background
384
394
} , {
385
395
pattern : / ^ \n / ,
386
396
sub : newline
387
- } , {
397
+ } , {
388
398
pattern : / ^ \r + \n / ,
389
399
sub : newline
390
400
} , {
@@ -486,7 +496,7 @@ class Filter {
486
496
* @param {boolean= } options.stream Save style state across invocations of `toHtml()`.
487
497
* @param {(string[] | {[code: number]: string})= } options.colors Can override specific colors or the entire ANSI palette.
488
498
*/
489
- constructor ( options ) {
499
+ constructor ( options ) {
490
500
options = options || { } ;
491
501
492
502
if ( options . colors ) {
@@ -501,7 +511,7 @@ class Filter {
501
511
* @param {string | string[] } input
502
512
* @returns {string }
503
513
*/
504
- toHtml ( input ) {
514
+ toHtml ( input ) {
505
515
input = typeof input === 'string' ? [ input ] : input ;
506
516
const { stack, options} = this ;
507
517
const buf = [ ] ;
0 commit comments