convert

Function convert 

Source
pub fn convert(ansi_string: &str) -> Result<String, Error>
Expand description

Converts a string containing ANSI escape codes to HTML.

Special html characters (<>&'") are escaped prior to the conversion. The number of generated HTML tags is minimized.

This behaviour can be customized by using the Converter builder.

ยงExample

let bold = "\x1b[1m";
let red = "\x1b[31m";
let input = format!("<h1> {bold}Hello {red}world! </h1>");
let converted = ansi_to_html::convert(&input).unwrap();

assert_eq!(
    converted,
    "&lt;h1&gt; <b>Hello <span style='color:var(--red,#a00)'>world! &lt;/h1&gt;</span></b>",
);