JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1733289
  • Score
    100M100P100Q202481F
  • License

Convert ansi escaped text streams to html.

Package Exports

  • ansi-to-html

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ansi-to-html) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Ansi to Html

This is a port of the ansi to html converter from bcat to Javascript.

It has a few additions:

  • The API has been altered to accept options in the constructor, and input in toHtml().
  • ANSI codes for setting the foreground or background color to default are handled. Default foreground and background colors can be set with the fg and bg options.
  • Newlines are converted to <br/> if the newline option is true
  • HTML/XML entitites are generated if the escapeXML option is true
  • the 'erase in line' escape code (\x1b[K) is dropped from the output.

Installation

npm install ansi-to-html

Usage

var Convert = require('ansi-to-html');

var convert = new Convert();

/*
    Or with options in the constructor
    var convert = new Convert({newLine: true, fg: 'white', bg: 'black'});
*/

console.log(convert.toHtml('\x1b[30mblack\x1b[37mwhite'));

/*
    prints:
    <span style="color:#000">black<span style="color:#AAA">white</span></span>
*/

Development

Once you have the git repository cloned, install the dependencies:

cd ansi-to-html
npm install

If you don't have it already, install the grunt command-line tool:

npm install -g grunt-cli

Build and test

grunt

All the time

grunt watch

Or separately

grunt coffee
grunt simplemocha  # or npm test