Crate hlight

source ·
Expand description

hlight

A library for output syntax highlighting.

Quick Start

add dep

cargo add hlight
use hlight::{gen_syntax_highlight, theme::theme_ayu_dark, HighLightRes};


let s: &str = r#"
[main]
enabled = false
"😎" = "🍥"
float = nan
"#;

let mut res = HighLightRes::default().with_background(false);
// theme_ayu_dark: Cow::from("ayu-dark")
*res.get_name_mut() = theme_ayu_dark();

gen_syntax_highlight("toml", s, Some(&res), None)
    .expect("Failed to get highlighted toml text");

output:

    [main]
    enabled = false
    "aa" = "bb"
    float = nan

use std::borrow::Cow;
*res.get_name_mut() = Cow::from("OneHalfLight");

gen_syntax_highlight("toml", s, Some(&res), None)?;

output:

    [main]
    enabled = false
    "😎" = "🍥"
    float = nan

write to file

use std::fs::File;

let mut file = File::create("test.txt").expect("Failed to create test.txt");
gen_syntax_highlight("toml", s, Some(&res), Some(&mut file))
    .expect("Unable to write syntax-highlighted text to file.")

Modules

Structs

Functions

  • Prints syntax-highlighted code to either standard output or a provided writer, using the selected syntax highlighting style to highlight the code beforehand.