4 releases

0.2.1 Nov 30, 2023
0.1.3 Mar 29, 2023
0.1.2 Sep 8, 2022
0.1.0 Nov 13, 2020

#92 in Command-line interface

Download history 1468/week @ 2023-12-02 1673/week @ 2023-12-09 1712/week @ 2023-12-16 1576/week @ 2023-12-23 1525/week @ 2023-12-30 1709/week @ 2024-01-06 2277/week @ 2024-01-13 1447/week @ 2024-01-20 1544/week @ 2024-01-27 2635/week @ 2024-02-03 2123/week @ 2024-02-10 1502/week @ 2024-02-17 1869/week @ 2024-02-24 2036/week @ 2024-03-02 1405/week @ 2024-03-09 2109/week @ 2024-03-16

7,582 downloads per month
Used in 7 crates

MIT license

32KB
635 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

~2.5–4MB
~74K SLoC