agnoster / ansi2html Goto Github PK
View Code? Open in Web Editor NEWConvert text with ANSI escape sequences to styled HTML
License: MIT License
Convert text with ANSI escape sequences to styled HTML
License: MIT License
Very useful library. Can you please add to bower?
We found an issue in the ANSI code matching that doesn't work well with a couple different ANSI combinations.
Case 1:
If a user has the valid code of 0;33;49m
, the logic only identifies 0
and 33
for conversion to HTML and ignores 49
.
We found a much older variant of the code, which I can no longer find in the history (or perhaps was from another library this one forked from way back when) didn't specifically choose slots 1 and 2, but rather just iterated through all:
return str.replace(/\x1b\[([0-9\;]+)m/g, function(match, codeSequence) {
var i, code, res = ''
codes = codeSequence.split(';')
for (i = 0; i < codes.length; i++) {
if (!codes[i]) continue
code = parseInt(codes[i])
res = tag(code)
}
return res
}) + tag();
Case 2:
If a user has the valid code of ;33m
, the logic only identifies 33
and ignores the leading semicolon. According to [the spec](www.ecma-international.org/publications/files/ECMA-ST/ECMA-48, 3rd Edition, March 1984.pdf) (5.4.11), a leading semicolon should be treated as an empty value; an empty value should be treated as 0
. In short: ;33m
== 0;33m
.
I'm using tput ( tput setaf
, tput bold
, tput setab
)
And these examples won't color properly or will have extra characters (B
or [
:
^[[1m^[[31m^[[47mlight-red_on_white^[(B^[[0m
^[[33m^[[44myellow_on_blue^[(B^[[0m
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.