diff --git a/src/blog.rs b/src/blog.rs index 9acea93..a78ab70 100644 --- a/src/blog.rs +++ b/src/blog.rs @@ -120,7 +120,7 @@ impl Post { // library updates. Updaing this value invalidates all // existing cache and they will be recompiled when someone // visits. -const CACHE_VERSION: &'static str = "0015"; +const CACHE_VERSION: &'static str = "0017"; // The prefix path used for caching remote images pub const IMG_CACHE_PREFIX: &'static str = "/imgcache/"; diff --git a/src/hljs.rs b/src/hljs.rs index 7dbdc17..5e1dd46 100644 --- a/src/hljs.rs +++ b/src/hljs.rs @@ -12,6 +12,11 @@ pub fn highlight_auto(code: &str) -> String { } pub fn highlight(lang: &str, code: &str) -> String { - Reflect::get(&hljs_highlight(lang, code), &"value".into()) - .unwrap().as_string().unwrap() + match hljs_highlight(lang, code) { + Ok(res) => Reflect::get(&res, &"value".into()) + .unwrap().as_string().unwrap(), + // This can throw error if `lang` is not supported + // or not imported by build.rs (and thus config.json) + Err(_) => code.to_owned() + } } \ No newline at end of file diff --git a/src/hljs_tpl.rs b/src/hljs_tpl.rs index 19d16bd..9004953 100644 --- a/src/hljs_tpl.rs +++ b/src/hljs_tpl.rs @@ -2,6 +2,6 @@ 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; + #[wasm_bindgen(catch, js_name = "highlight")] + fn hljs_highlight(lang: &str, code: &str) -> Result; } \ No newline at end of file