4 个版本
0.1.3 | 2022年8月17日 |
---|---|
0.1.2 | 2022年8月15日 |
0.1.1 | 2022年8月15日 |
0.1.0 | 2022年8月15日 |
#229 在 文本编辑器
32 每月下载量
455KB
12K SLoC
hl_core
Github 风格的 Rust 语法高亮器。在浏览器中查看结果这里。
示例
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)
}
运行
cargo run html examples/html.rs