#color #cli #terminal #html

ansi-to-html

ANSI escape codes to HTML converter

1 unstable release

0.1.0 Nov 13, 2020

#104 in #color

Download history 867/week @ 2021-04-03 1125/week @ 2021-04-10 1186/week @ 2021-04-17 1560/week @ 2021-04-24 1574/week @ 2021-05-01 1640/week @ 2021-05-08 2038/week @ 2021-05-15 1721/week @ 2021-05-22 1017/week @ 2021-05-29 1890/week @ 2021-06-05 2017/week @ 2021-06-12 2160/week @ 2021-06-19 2134/week @ 2021-06-26 1808/week @ 2021-07-03 1357/week @ 2021-07-10 923/week @ 2021-07-17

3,356 downloads per month
Used in to-html

MIT license

21KB
437 lines

ansi-to-html

Documentation

Rust library to convert a string that can contain ANSI escape codes to HTML.

This crate currently supports SGR parameters (text style and colors). The supported styles are:

  • bold
  • italic
  • underlined
  • crossed out
  • faint
  • foreground and background colors: 3-bit, 4-bit, 8-bit, truecolor (24-bit)

Not supported SGR parameters (note that most of these are niche features and rarely supported by terminals):

  • slow/rapid blink
  • reverse video
  • conceal
  • alternative fonts
  • fraktur
  • doubly underlined
  • proportional spacing
  • framed
  • encircled
  • overlined
  • underline color (not in standard)
  • ideogram attributes
  • superscript, subscript (not in standard)
  • bright foreground/background color (not in standard)

All unsupported ANSI escape codes are stripped from the output.

It should be easy to add support for more styles, if there's a straightforward HTML representation. If you need a different style (e.g. doubly underlined), file an issue.

Features

When the lazy-init feature is enabled, regexes are lazily initialized, which is more efficient if you want to convert A LOT of strings. The performance difference has not been tested.

Dependencies

~1.4–2.2MB
~59K SLoC