#syntax-highlighting #js #bindings #prism #spans #highlight #class

prism-js

rust bindings for prism.js syntax highlighting library

3 releases

0.1.2 Jun 5, 2023
0.1.1 Jun 2, 2023
0.1.0 Jun 2, 2023

#297 in Text editors

38 downloads per month

MIT license

585KB
320 lines

prism-rs

Rust bindings for Prism syntax highlighting.

Usage

[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>

Dependencies

~2.5MB
~78K SLoC