Crates.io | prism-js |
lib.rs | prism-js |
version | 0.1.2 |
source | src |
created_at | 2023-06-02 23:21:43.893129 |
updated_at | 2023-06-05 14:13:17.363611 |
description | rust bindings for prism.js syntax highlighting library |
homepage | |
repository | https://github.com/FraserLee/prism-rs |
max_upload_size | |
id | 881266 |
size | 587,441 |
Rust bindings for Prism syntax highlighting.
[dependencies]
prism-js = "0.1"
use prism_js::{init, highlight}
let mut context = init();
let lang = "haskell";
let code = r#"
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
main = print $ take 100 fibs
"#;
let html = highlight(&mut context, code, lang);
println!("{}", html.unwrap());
which outputs:
<span class="token hvariable">fibs</span> <span class="token operator">=</span>
<span class="token number">0</span> <span class="token operator">:</span> <span
class="token number">1</span> <span class="token operator">:</span> <span
class="token builtin">zipWith</span> <span class="token
punctuation">(</span><span class="token operator">+</span><span class="token
punctuation">)</span> <span class="token hvariable">fibs</span> <span
class="token punctuation">(</span><span class="token builtin">tail</span> <span
class="token hvariable">fibs</span><span class="token punctuation">)</span>
<span class="token hvariable">main</span> <span class="token operator">=</span>
<span class="token builtin">print</span> <span class="token operator">$</span>
<span class="token builtin">take</span> <span class="token number">100</span>
<span class="token hvariable">fibs</span>