#语法高亮 #js #绑定 #prism #spans #高亮 #

prism-js

为Prism.js语法高亮库提供的Rust绑定

3个版本

0.1.2 2023年6月5日
0.1.1 2023年6月2日
0.1.0 2023年6月2日

297文本编辑器

每月下载量38次

MIT 许可证

585KB
320

prism-rs

Prism语法高亮提供的Rust绑定。

用法

[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());

输出结果

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

依赖项

~2.5MB
~78K SLoC