aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordelta <darkussdelta@gmail.com>2025-08-26 02:29:03 +0200
committerdelta <darkussdelta@gmail.com>2025-08-26 02:29:57 +0200
commitaced62ade1363ae031114302ec69dbc7f6f38a10 (patch)
treefd571ef2c654fd024d74b81d7779c95f6b356957
parentcfd14e880023752bffe9a01d1781b54ceefa32ec (diff)
html decode the input before highlighting
-rw-r--r--Cargo.lock16
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs4
3 files changed, 20 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7a75cc9..e2fb471 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -97,6 +97,15 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -502,6 +511,12 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -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::<Vec<String>>().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 <lang> <code> as arguments")
+ panic!("Need <lang> <code> as arguments, got {:?}", args().collect::<Vec<String>>())
}
}