summaryrefslogtreecommitdiff
path: root/docs/src/html.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-06-30 16:17:52 +0200
committerLaurenz <laurmaedje@gmail.com>2023-06-30 16:17:52 +0200
commitd1a7a6dbab1e59936c0dcd4278e584fe739e9aaa (patch)
tree329fc4d51299d558f750325c5762fe26e3c5a14d /docs/src/html.rs
parent5b4f4c164bc42802763c9f9d0121f81ebf116761 (diff)
Non-Typst highlighting in documentation
Diffstat (limited to 'docs/src/html.rs')
-rw-r--r--docs/src/html.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/docs/src/html.rs b/docs/src/html.rs
index e1f294ee..f5fceb12 100644
--- a/docs/src/html.rs
+++ b/docs/src/html.rs
@@ -1,7 +1,6 @@
use std::ops::Range;
use comemo::Prehashed;
-use md::escape::escape_html;
use pulldown_cmark as md;
use typed_arena::Arena;
use typst::diag::FileResult;
@@ -402,11 +401,22 @@ fn code_block(resolver: &dyn Resolver, lang: &str, text: &str) -> Html {
}
}
- if !matches!(lang, "example" | "typ") {
+ if lang.is_empty() {
let mut buf = String::from("<pre>");
- escape_html(&mut buf, &display).unwrap();
+ md::escape::escape_html(&mut buf, &display).unwrap();
buf.push_str("</pre>");
return Html::new(buf);
+ } else if !matches!(lang, "example" | "typ") {
+ let set = &*typst_library::text::SYNTAXES;
+ let buf = syntect::html::highlighted_html_for_string(
+ &display,
+ set,
+ set.find_syntax_by_token(lang)
+ .unwrap_or_else(|| panic!("unsupported highlighting language: {lang}")),
+ &typst_library::text::THEME,
+ )
+ .expect("failed to highlight code");
+ return Html::new(buf);
}
let root = typst::syntax::parse(&display);