Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

ansi-to-html

> 编程语言
Open source

Convert ansi escaped text streams to html.

377 stars0 likes3 views
WebsiteGitHub

About

Convert ansi escaped text streams to html.

Ansi to Html

This was originally a port of the ansi to html converter from bcat to JavaScript. It has since undergone quite a lot of modification.

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
  • the 'erase in line' escape code (\x1b[K) is dropped from the output.

Installation

bash
npm install ansi-to-html

Usage

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

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

/*
    prints:
    blackwhite
*/

Command line usage

When using ansi-to-html from the command line the stream option is set to true. Other options can be provided. See ansi-to-html -h for more detail.

Process a file

bash
ansi-to-html the_filename

From STDIN

bash
git log | ansi-to-html

Options

Options can be be passed to the constructor to customize behaviour.

fg ``. The default foreground color used when reset color codes are encountered.

bg ``. The default background color used when reset color codes are encountered.

newline true or false. Convert newline characters to .

escapeXML true or false. Generate HTML/XML entities.

stream true or false. Save style state across invocations of toHtml().

colors Object/Array (with values 0 - 255 containing CSS color values). Can override specific colors or the entire ANSI palette

Default options

json5
{
    fg: '#FFF',
    bg: '#000',
    newline: false,
    escapeXML: false,
    stream: false
}

Development

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

bash
cd ansi-to-html
npm install

Lint

bash
npm run lint

Test

bash
npm test
  • Note: Runs the tests against the source files (in the /lib directory).
  • You also run the tests in watch mode (will rerun tests when files are changed).
  • Recommended to run the build in watch mode as well to re-build the project before the tests are run.
bash
npm run test:watch

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言