hl_core 0.1.3

Syntax highlighting in Rust
Documentation
  • Coverage
  • 0%
    0 out of 388 items documented0 out of 224 items with examples
  • Size
  • Source code size: 451.21 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.71 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ahmadrosid

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