4 releases

0.1.3 Aug 17, 2022
0.1.2 Aug 15, 2022
0.1.1 Aug 15, 2022
0.1.0 Aug 15, 2022

#227 in Text editors

MIT license

455KB
12K SLoC

hl_core

Github like Syntax highlighter in rust. See the result in browser here.

Example

use std::path::Path;

use hl::render_html;
use std::fs::read_to_string;

fn main() {
    let file_path = std::env::args().nth(1).unwrap_or(String::new());
    let language_flag = std::env::args().nth(2).unwrap_or(String::new());
    let lang = std::env::args().nth(3).unwrap_or(String::from("raw"));

    let path = Path::new(&file_path);
    if !path.exists() {
        println!("File path not found! {}", &file_path);
        std::process::exit(1);
    }

    if language_flag.is_empty() {
        println!("Language flag is required! e.g -l javascript");
        std::process::exit(1);
    }

    let input = read_to_string(path).unwrap().chars().collect::<Vec<_>>();
    let result = render_html(input, &lang);
    print!("{}", result)
}

Run

cargo run html examples/html.rs

No runtime deps