Code Monkey home page Code Monkey logo

ansi2html's People

Contributors

agnoster avatar dtinth avatar mixu avatar tobeportable avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ansi2html's Issues

No accommodation for leading semicolon or > 2 codes

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.

support for tput colored text

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.