feat: setup for tree-sitter syntax highlighting

This commit is contained in:
Jan-Bulthuis committed 2026-07-19 15:20:38 +02:00
1 parent 853efc406d
commit d5ecc05345
5 files changed
+233 -8

No files matched your search

+9 -1
View File
@@ -5,7 +5,7 @@ use tracing::info;
use typst::{
Library, LibraryExt, World,
diag::{FileError, FileResult, PackageError, PackageResult, SourceDiagnostic},
foundations::{Bytes, Datetime, Duration},
foundations::{Bytes, Datetime, Dict, Duration, Value},
syntax::{FileId, RootedPath, Source, VirtualPath, VirtualRoot, package::PackageSpec},
text::{Font, FontBook},
utils::LazyHash,
@@ -23,7 +23,15 @@ pub struct TypstContext {
impl TypstContext {
pub fn new(config: AppConfig) -> Self {
let mut inputs = Dict::new();
if config.syntax_root.is_some() {
inputs.insert(
"highlight".into(),
Value::Func(crate::syntax::highlight_func()),
);
}
let library = Library::builder()
.with_inputs(inputs)
.with_features([typst::Feature::Html].into_iter().collect())
.build();
let library = LazyHash::new(library);