From aced62ade1363ae031114302ec69dbc7f6f38a10 Mon Sep 17 00:00:00 2001 From: delta Date: Tue, 26 Aug 2025 02:29:03 +0200 Subject: html decode the input before highlighting --- Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 1 + src/main.rs | 4 +++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 7a75cc9..e2fb471 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -96,6 +96,15 @@ version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +[[package]] +name = "html-escape" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d1ad449764d627e22bfd7cd5e8868264fc9236e07c752972b4080cd351cb476" +dependencies = [ + "utf8-width", +] + [[package]] name = "icu_collections" version = "2.0.0" @@ -501,6 +510,12 @@ dependencies = [ "serde", ] +[[package]] +name = "utf8-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3" + [[package]] name = "utf8_iter" version = "1.0.4" @@ -604,6 +619,7 @@ name = "yah" version = "0.1.0" dependencies = [ "dirs", + "html-escape", "libloading", "tree-sitter", "tree-sitter-highlight", diff --git a/Cargo.toml b/Cargo.toml index 25da5ac..ccc6bd8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ edition = "2024" [dependencies] dirs = "6.0.0" +html-escape = "0.2.13" libloading = "0.8.8" tree-sitter = "0.25.8" tree-sitter-highlight = "0.25.8" diff --git a/src/main.rs b/src/main.rs index d96cc46..0904b55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -148,6 +148,8 @@ fn get_config<'a>( fn main() { if let [_, lang, code] = args().collect::>().as_slice() { + // decode code as it may be html encoded + let code = html_escape::decode_html_entities(code); let mut highlighter = Highlighter::new(); let configs = RefCell::new(HashMap::new()); @@ -174,6 +176,6 @@ fn main() { }).unwrap(); print!("{}", String::from_utf8(renderer.html).unwrap()) } else { - panic!("Need as arguments") + panic!("Need as arguments, got {:?}", args().collect::>()) } } -- cgit v1.2.3