Comparing version 5.0.1 to 5.1.0
@@ -37,6 +37,8 @@ /* ansi_up.js | ||
function AnsiUp() { | ||
this.VERSION = "5.0.1"; | ||
this.VERSION = "5.1.0"; | ||
this.setup_palettes(); | ||
this._use_classes = false; | ||
this.bold = false; | ||
this.italic = false; | ||
this.underline = false; | ||
this.fg = this.bg = null; | ||
@@ -270,3 +272,3 @@ this._buffer = ''; | ||
AnsiUp.prototype.with_state = function (pkt) { | ||
return { bold: this.bold, fg: this.fg, bg: this.bg, text: pkt.text }; | ||
return { bold: this.bold, italic: this.italic, underline: this.underline, fg: this.fg, bg: this.bg, text: pkt.text }; | ||
}; | ||
@@ -281,2 +283,4 @@ AnsiUp.prototype.process_ansi = function (pkt) { | ||
this.bold = false; | ||
this.italic = false; | ||
this.underline = false; | ||
} | ||
@@ -286,5 +290,17 @@ else if (num === 1) { | ||
} | ||
else if (num === 3) { | ||
this.italic = true; | ||
} | ||
else if (num === 4) { | ||
this.underline = true; | ||
} | ||
else if (num === 22) { | ||
this.bold = false; | ||
} | ||
else if (num === 23) { | ||
this.italic = false; | ||
} | ||
else if (num === 24) { | ||
this.underline = false; | ||
} | ||
else if (num === 39) { | ||
@@ -342,3 +358,3 @@ this.fg = null; | ||
txt = this.escape_txt_for_html(txt); | ||
if (!fragment.bold && fragment.fg === null && fragment.bg === null) | ||
if (!fragment.bold && !fragment.italic && !fragment.underline && fragment.fg === null && fragment.bg === null) | ||
return txt; | ||
@@ -351,2 +367,6 @@ var styles = []; | ||
styles.push('font-weight:bold'); | ||
if (fragment.italic) | ||
styles.push('font-style:italic'); | ||
if (fragment.underline) | ||
styles.push('text-decoration:underline'); | ||
if (!this._use_classes) { | ||
@@ -353,0 +373,0 @@ if (fg) |
@@ -26,2 +26,4 @@ /* ansi_up.js | ||
bold:boolean; | ||
italic: boolean; | ||
underline: boolean; | ||
text:string; | ||
@@ -54,3 +56,3 @@ } | ||
{ | ||
VERSION = "5.0.1"; | ||
VERSION = "5.1.0"; | ||
@@ -69,3 +71,4 @@ // | ||
private bold:boolean; | ||
private italic: boolean; | ||
private underline:boolean; | ||
private _use_classes:boolean; | ||
@@ -89,2 +92,4 @@ | ||
this.bold = false; | ||
this.italic = false; | ||
this.underline = false; | ||
this.fg = this.bg = null; | ||
@@ -545,3 +550,3 @@ | ||
private with_state(pkt:TextPacket):TextWithAttr { | ||
return { bold: this.bold, fg: this.fg, bg: this.bg, text: pkt.text }; | ||
return { bold: this.bold, italic: this.italic, underline: this.underline, fg: this.fg, bg: this.bg, text: pkt.text }; | ||
} | ||
@@ -566,6 +571,16 @@ | ||
this.bold = false; | ||
this.italic = false; | ||
this.underline = false; | ||
} else if (num === 1) { | ||
this.bold = true; | ||
} else if (num === 3) { | ||
this.italic = true; | ||
} else if (num === 4) { | ||
this.underline = true; | ||
} else if (num === 22) { | ||
this.bold = false; | ||
} else if (num === 23) { | ||
this.italic = false; | ||
} else if (num === 24) { | ||
this.underline = false; | ||
} else if (num === 39) { | ||
@@ -633,3 +648,3 @@ this.fg = null; | ||
// If colors not set, default style is used | ||
if (!fragment.bold && fragment.fg === null && fragment.bg === null) | ||
if (!fragment.bold && !fragment.italic && !fragment.underline && fragment.fg === null && fragment.bg === null) | ||
return txt; | ||
@@ -645,4 +660,10 @@ | ||
if (fragment.bold) | ||
styles.push('font-weight:bold') | ||
styles.push('font-weight:bold'); | ||
if (fragment.italic) | ||
styles.push('font-style:italic'); | ||
if (fragment.underline) | ||
styles.push('text-decoration:underline'); | ||
if (!this._use_classes) { | ||
@@ -649,0 +670,0 @@ // USE INLINE STYLES |
@@ -9,2 +9,4 @@ export interface AU_Color { | ||
bold: boolean; | ||
italic: boolean; | ||
underline: boolean; | ||
text: string; | ||
@@ -33,2 +35,4 @@ } | ||
private bold; | ||
private italic; | ||
private underline; | ||
private _use_classes; | ||
@@ -35,0 +39,0 @@ private _csi_regex; |
{ | ||
"name": "ansi_up", | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"description": "Convert ansi sequences in strings to colorful HTML", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -76,2 +76,3 @@ # ansi_up.js | ||
## Versions | ||
* Version 5.1 - Add italic and underline styles (@DaoDaoNoCode) | ||
* Version 5.0 - Security fix for OSC URLs | ||
@@ -186,2 +187,3 @@ * Version 4.0 - Re-architect code to support [terminal URL codes](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda). | ||
- Juntao Wang (<https://github.com/DaoDaoNoCode>) | ||
- AIZAWA Hina (<https://github.com/fetus-hina>) | ||
@@ -188,0 +190,0 @@ - James R. White (<https://github.com/jamesrwhite>) |
@@ -278,2 +278,26 @@ var AU = require('../ansi_up'); | ||
it('should transform an italic attr;foreground to html', function () { | ||
var attr = 3; | ||
var fg = 32; | ||
var start = "\033[" + attr + ";" + fg + "m " + attr + ";" + fg + " \033[0m"; | ||
var expected = "<span style=\"font-style:italic;color:rgb(0,187,0)\"> " + attr + ";" + fg + " </span>"; | ||
var au = new AnsiUp(); | ||
var l = au.ansi_to_html(start); | ||
l.should.eql(expected); | ||
}); | ||
it('should transform an underline attr;foreground to html', function () { | ||
var attr = 4; | ||
var fg = 32; | ||
var start = "\033[" + attr + ";" + fg + "m " + attr + ";" + fg + " \033[0m"; | ||
var expected = "<span style=\"text-decoration:underline;color:rgb(0,187,0)\"> " + attr + ";" + fg + " </span>"; | ||
var au = new AnsiUp(); | ||
var l = au.ansi_to_html(start); | ||
l.should.eql(expected); | ||
}); | ||
it('should transform a bright-foreground to html', function () { | ||
@@ -537,2 +561,30 @@ var fg = 92; | ||
it('should transform an italic attr;background;bright-foreground to html', function () { | ||
var attr = 3; | ||
var fg = 33; | ||
var bg = 102; | ||
var start = "\033[" + attr + ";" + bg + ";" + fg + "m " + attr + ";" + bg + ";" + fg + " \033[0m"; | ||
var expected = '<span style="font-style:italic"' + " class=\"ansi-yellow-fg ansi-bright-green-bg\"> " + attr + ";" + bg + ";" + fg + " </span>"; | ||
var au = new AnsiUp(); | ||
au.use_classes = true; | ||
var l = au.ansi_to_html(start); | ||
l.should.eql(expected); | ||
}); | ||
it('should transform an underline attr;background;bright-foreground to html', function () { | ||
var attr = 4; | ||
var fg = 33; | ||
var bg = 102; | ||
var start = "\033[" + attr + ";" + bg + ";" + fg + "m " + attr + ";" + bg + ";" + fg + " \033[0m"; | ||
var expected = '<span style="text-decoration:underline"' + " class=\"ansi-yellow-fg ansi-bright-green-bg\"> " + attr + ";" + bg + ";" + fg + " </span>"; | ||
var au = new AnsiUp(); | ||
au.use_classes = true; | ||
var l = au.ansi_to_html(start); | ||
l.should.eql(expected); | ||
}); | ||
it('should transform a complex multi-line sequence to html', function () { | ||
@@ -668,8 +720,2 @@ var attr = 1; | ||
}); | ||
it('(italic)', function () { | ||
var start = "foo\033[3mbar\033[0mbaz"; | ||
var au = new AnsiUp(); | ||
var l = au.ansi_to_html(start); | ||
l.should.eql('foobarbaz'); | ||
}); | ||
it('(cursor-up)', function () { | ||
@@ -676,0 +722,0 @@ var start = "foo\033[1Abar"; |
Sorry, the diff of this file is not supported yet
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
278597
2234
193