pub fn convert_with_opts(input: &str, opts: &Opts) -> Result<String, Error>
Expand description

Converts a string containing ANSI escape codes to HTML with customized behavior.

If escaped is true, then special html characters (<>&'") are escaped prior to the conversion.

If optimized is true, this function attempts to minimize the number of generated HTML tags. Set it to false if you want optimal performance.

Example

use ansi_to_html::{convert_with_opts, Opts};

let opts = Opts::default()
    .skip_escape(true)
    .skip_optimize(true)
    .four_bit_var_prefix(Some("custom-".to_owned()));
let bold = "\x1b[1m";
let red = "\x1b[31m";
let reset = "\x1b[0m";
let input = format!("<h1> <i></i> {bold}Hello {red}world!{reset} </h1>");
let converted = convert_with_opts(&input, &opts).unwrap();

assert_eq!(
    converted,
    // The `<h1>` and `</h1>` aren't escaped, useless `<i></i>` is kept, and
    // `<span class='red'>` is used instead of `<span style='color:#a00'>`
    "<h1> <i></i> <b>Hello <span style='color:var(--custom-red,#a00)'>world!</span></b> </h1>",
);