2 releases

0.1.2 Sep 8, 2022
0.1.0 Nov 13, 2020

#192 in Command-line interface

Download history 1144/week @ 2022-10-09 311/week @ 2022-10-16 356/week @ 2022-10-23 412/week @ 2022-10-30 136/week @ 2022-11-06 267/week @ 2022-11-13 178/week @ 2022-11-20 199/week @ 2022-11-27 238/week @ 2022-12-04 183/week @ 2022-12-11 272/week @ 2022-12-18 87/week @ 2022-12-25 321/week @ 2023-01-01 598/week @ 2023-01-08 527/week @ 2023-01-15 401/week @ 2023-01-22

1,847 downloads per month
Used in 3 crates

MIT license

25KB
471 lines

ansi-to-html

Documentation

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

ANSI support

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.1–2MB
~52K SLoC