1. Use hljs and wasm_bindgen to parse code 2. Allow the final user to choose what language to include by generating inline_js in build.rs for #[wasm_bindgen] (a thin wrapper around the raw hljs to load whatever is needed by config.json statically rather than dynamically) 3. Integrate the monokai color scheme into our default thememaster
parent
26bb98b11e
commit
f519152465
@ -0,0 +1,17 @@
|
||||
// Simple bindings for Highlight.js
|
||||
// We don't have something equivalent in Rust
|
||||
// and I don't really want to run these on client
|
||||
use js_sys::Reflect;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/load_hljs.rs"));
|
||||
|
||||
pub fn highlight_auto(code: &str) -> String {
|
||||
Reflect::get(&hljs_highlight_auto(code), &"value".into())
|
||||
.unwrap().as_string().unwrap()
|
||||
}
|
||||
|
||||
pub fn highlight(lang: &str, code: &str) -> String {
|
||||
Reflect::get(&hljs_highlight(lang, code), &"value".into())
|
||||
.unwrap().as_string().unwrap()
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
// Will be loaded by build.rs and add #[wasm_bindgen(inline_js = "...")] here
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_name = "highlightAuto")]
|
||||
fn hljs_highlight_auto(code: &str) -> JsValue;
|
||||
#[wasm_bindgen(js_name = "highlight")]
|
||||
fn hljs_highlight(lang: &str, code: &str) -> JsValue;
|
||||
}
|
@ -0,0 +1 @@
|
||||
../../../node_modules/highlight.js/styles/monokai-sublime.css
|
Loading…
Reference in new issue