ansi-to-html
Advanced tools
Comparing version 0.6.8 to 0.6.9
@@ -111,2 +111,4 @@ 'use strict'; | ||
result = pushForegroundColor(stack, options.colors[data]); | ||
} else if (token === 'rgb') { | ||
result = handleRgb(stack, data); | ||
} | ||
@@ -119,2 +121,19 @@ | ||
* @param {Array} stack | ||
* @param {string} data | ||
* @returns {*} | ||
*/ | ||
function handleRgb(stack, data) { | ||
data = data.substring(2).slice(0, -1); | ||
var operation = +data.substr(0, 2); | ||
var color = data.substring(5).split(';'); | ||
var rgb = color.map(function (value) { | ||
return ('0' + Number(value).toString(16)).substr(-2); | ||
}).join(''); | ||
return pushStyle(stack, (operation === 38 ? 'color:#' : 'background-color:#') + rgb); | ||
} | ||
/** | ||
* @param {Array} stack | ||
* @param {number} code | ||
@@ -372,2 +391,8 @@ * @param {object} options | ||
function rgb(m) { | ||
callback('rgb', m); | ||
return ''; | ||
} | ||
/* eslint no-control-regex:0 */ | ||
@@ -384,2 +409,5 @@ var tokens = [{ | ||
}, { | ||
pattern: /^\x1b\[[34]8;2;\d+;\d+;\d+m/, | ||
sub: rgb | ||
}, { | ||
pattern: /^\x1b\[38;5;(\d+)m/, | ||
@@ -386,0 +414,0 @@ sub: removeXterm256 |
{ | ||
"name": "ansi-to-html", | ||
"version": "0.6.8", | ||
"version": "0.6.9", | ||
"description": "Convert ansi escaped text streams to html.", | ||
@@ -75,4 +75,6 @@ "main": "lib/ansi_to_html.js", | ||
"babel": { | ||
"presets": ["env"] | ||
"presets": [ | ||
"env" | ||
] | ||
} | ||
} |
@@ -151,2 +151,16 @@ /* globals describe, it*/ | ||
it('renders foreground rgb sequences', function (done) { | ||
const text = '\x1b[38;2;210;60;114mhello'; | ||
const result = '<span style="color:#d23c72">hello</span>'; | ||
return test(text, result, done); | ||
}); | ||
it('renders background rgb sequences', function (done) { | ||
const text = '\x1b[48;2;155;42;45mhello'; | ||
const result = '<span style="background-color:#9b2a2d">hello</span>'; | ||
return test(text, result, done); | ||
}); | ||
it('handles resetting to default foreground color', function (done) { | ||
@@ -153,0 +167,0 @@ const text = '\x1b[30mblack\x1b[39mdefault'; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37334
887