ansi-to-html

Converts ANSI escape sequences from terminal output into styled HTML spans, with a bundled CLI for piping colored logs straight to HTML.

Library
npm
v0.7.2
376stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
36/100Needs Attention
Development Activity0
Maintenance0
Community64
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
61/100Good
Architecture70
Code Quality65
Innovation75
Learning Curve35

ansi-to-html is a small, focused Node.js library that turns raw ANSI-escaped terminal output — the kind produced by colored console logs, CI build output, or git log — into semantically equivalent HTML markup. It ships a Filter class with a single toHtml() method, so any tool that captures terminal output (a log viewer, a CI dashboard, a build-status page) can render it in a browser with the original colors, bold/underline/strike styling, and 256-color/truecolor support preserved.

Beyond the library API, the package installs an ansi-to-html CLI binary that reads from a file or stdin and streams converted HTML to stdout, making it usable directly in shell pipelines (git log | ansi-to-html > log.html). It originated as a JavaScript port of a Ruby ANSI-to-HTML converter from the bcat project and has been maintained and extended by the community since 2012.

What You Get

  • A Filter class (new Convert(options)) with a toHtml(input) method that accepts a string or array of strings and returns HTML
  • Full ANSI SGR support: 16-color and 256-color (xterm) foreground/background, 24-bit RGB truecolor, bold, italic, underline, strikethrough, and blink
  • A stream: true option that keeps style state ‘sticky’ across successive toHtml() calls for chunked/streamed input
  • An escapeXML option to HTML/XML-entity-escape the plain text portions of the output
  • A CLI binary (ansi-to-html) that reads a file or stdin and streams converted HTML to stdout, for use directly in shell pipelines
  • Configurable default/reset foreground and background colors, and a colors option to override individual palette entries or the entire 256-color table

Common Use Cases

  • Rendering colored CI/CD build logs in a web-based dashboard
  • Displaying git log, linter, or test-runner output with its original terminal coloring inside a browser-based UI
  • Building log-viewer or terminal-recording playback tools that need to preserve ANSI color/style information as HTML
  • Piping colorized CLI output into a static HTML file for sharing or archiving
  • Embedding live streamed terminal output (e.g. from a WebSocket-connected process) into a web page with correct styling

Under The Hood

Architecture The entire library is a single module (lib/ansi_to_html.js) built around a regex-driven tokenizer (tokenize()) and a small state machine. The tokenizer walks the input string against an ordered list of regex patterns — for backspaces, ANSI SGR sequences, 256-color and RGB escape codes, and CR/LF handling — replacing each match with an empty string and invoking a callback with a (token, data) pair as it goes. generateOutput() dispatches on the token type (text, display, xterm256Foreground, xterm256Background, rgb) to push or close HTML tags onto a stack array, which the Filter class flushes into a joined HTML string in toHtml(). When the stream option is set, an additional stickyStack — deduplicated by ANSI “category” (bold, underline, foreground-color, etc.) — carries open styles across separate toHtml() invocations, letting the converter be fed a stream in chunks (as the CLI’s htmlStream() does) rather than a single flat string. There is no dependency injection or multi-layer architecture; the design trades structure for a compact, single-purpose implementation, so the main risk if the core token grammar changes is that the ordered regex list and its short-circuiting logic (ansiHandler/ansiMatch) would need careful re-verification.

Tech Stack The package is plain CommonJS JavaScript (no TypeScript compilation, though a hand-written lib/ansi_to_html.d.ts ships type declarations) targeting Node.js >=8. Its only runtime dependency is entities (^4.0.0), used solely for XML-entity encoding when escapeXML is enabled. Development tooling is mocha + chai for tests, nyc for coverage reporting (text + HTML reporters), and ESLint for linting, wired into a CircleCI pipeline (.circleci/config.yml). There is no bundler or build step — the published package is the raw lib/ and bin/ source.

Code Quality Tests live in test/ansi_to_html.js and test/cli.js, using mocha’s describe/it structure and chai’s expect assertions, with dozens of cases covering plain text, CR/LF variants, 16-color, 256-color, RGB, bold/italic/underline/strike, streaming mode, and CLI flag handling — a genuinely comprehensive suite for the surface area involved. Naming is consistent and functions are short and single-purpose, with JSDoc comments on most helper functions. There is no static type-checking (plain JS, not TypeScript), and the .d.ts file is maintained by hand rather than generated, so type accuracy depends on manual upkeep rather than compiler enforcement.

API Design The public surface is deliberately minimal: instantiate new Convert(options) once, then call .toHtml(text) as many times as needed. Options are a flat object (fg, bg, newline, escapeXML, stream, colors) with sensible defaults, so a caller can get correct output with zero configuration and opt into streaming or custom palettes incrementally. The CLI mirrors the same options as flags (-n, -x, -f, -b), keeping the two interfaces conceptually aligned. The main friction point for new users is that behavior nuances (e.g. how stream mode’s sticky-style tracking interacts with resets) are only discoverable by reading the source or tests, since the README documents options but not these interaction details.

Used by 7 apps in this directory

JavaScript
51%
Apache 2.0

claude-mem

AI Agents · AI Development

93,347

Give your AI coding agents persistent memory — claude-mem captures everything that happens during sessions, compresses it with AI, and surfaces the right context in every future session automatically.

View details
86
Repo Health
82
Technical
77
Dependency
Built with
JavaScript51%
TypeScript47%
Updated yesterday
Ruby
60%
GPL 2.0

Discourse

Community

47,793

Open-source community platform with dynamic trust levels, real-time chat, and a powerful plugin architecture for self-hosted forums.

View details
89
Repo Health
89
Technical
67
Dependency
Built with
Ruby60%
JavaScript32%
Updated today
TypeScript
57%
MIT

Jitsu

Data Engineering

5,063

Open-source, fully-scriptable data ingestion engine that streams events from web, apps, and APIs to any data warehouse in real time.

View details
88
Repo Health
79
Technical
66
Dependency
Built with
TypeScript57%
Go41%
Updated 3 days ago
Java
59%
Apache 2.0

Kestra

Devops · Data Engineering · Automation

28,007

Event-driven orchestration platform for data, AI, and infrastructure workflows — define everything in YAML, run anywhere at scale.

View details
94
Repo Health
81
Technical
72
Dependency
Built with
Java59%
TypeScript25%
Vue15%
Updated yesterday
Python
68%
MIT

Langflow

AI Agents · AI Development

154,349

Build, test, and deploy AI agents and RAG workflows visually with native API and MCP server export.

View details
90
Repo Health
85
Technical
65
Dependency
Built with
Python68%
TypeScript23%
Updated today
TypeScript
97%
MIT

Promptfoo

AI Development

24,866

An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.

View details
90
Repo Health
73
Technical
68
Dependency
Built with
TypeScript97%
Updated today
TypeScript
50%
Other

SigNoz

Monitoring · Analytics

32,028

Self-host your entire observability stack — logs, metrics, traces, and LLM monitoring — in one OpenTelemetry-native platform, without the Datadog bill.

View details
92
Repo Health
83
Technical
67
Dependency
Built with
TypeScript50%
Go39%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search