From 7b92bd7c340d9f9c094ed2fa57912049317d9b20 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 26 Jun 2023 13:57:21 +0200 Subject: Basic package management --- docs/src/html.rs | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'docs/src/html.rs') diff --git a/docs/src/html.rs b/docs/src/html.rs index 78a43511..a6e58b73 100644 --- a/docs/src/html.rs +++ b/docs/src/html.rs @@ -6,10 +6,11 @@ use pulldown_cmark as md; use typed_arena::Arena; use typst::diag::FileResult; use typst::eval::Datetime; +use typst::file::FileId; use typst::font::{Font, FontBook}; use typst::geom::{Point, Size}; -use typst::syntax::{Source, SourceId}; -use typst::util::Buffer; +use typst::syntax::Source; +use typst::util::Bytes; use typst::World; use yaml_front_matter::YamlFrontMatter; @@ -414,7 +415,8 @@ fn code_block(resolver: &dyn Resolver, lang: &str, text: &str) -> Html { return Html::new(format!("
{}
", highlighted.as_str())); } - let source = Source::new(SourceId::from_u16(0), Path::new("main.typ"), compile); + let id = FileId::new(None, Path::new("main.typ")); + let source = Source::new(id, compile); let world = DocWorld(source); let mut frames = match typst::compile(&world) { Ok(doc) => doc.pages, @@ -461,7 +463,7 @@ fn nest_heading(level: &mut md::HeadingLevel) { }; } -/// World for example compilations. +/// A world for example compilations. struct DocWorld(Source); impl World for DocWorld { @@ -469,35 +471,31 @@ impl World for DocWorld { &LIBRARY } - fn main(&self) -> &Source { - &self.0 - } - - fn resolve(&self, _: &Path) -> FileResult { - unimplemented!() - } - - fn source(&self, id: SourceId) -> &Source { - assert_eq!(id.as_u16(), 0, "invalid source id"); - &self.0 - } - fn book(&self) -> &Prehashed { &FONTS.0 } - fn font(&self, id: usize) -> Option { - Some(FONTS.1[id].clone()) + fn main(&self) -> Source { + self.0.clone() + } + + fn source(&self, _: FileId) -> FileResult { + Ok(self.0.clone()) } - fn file(&self, path: &Path) -> FileResult { + fn file(&self, id: FileId) -> FileResult { + assert!(id.package().is_none()); Ok(FILES - .get_file(path) - .unwrap_or_else(|| panic!("failed to load {path:?}")) + .get_file(id.path()) + .unwrap_or_else(|| panic!("failed to load {:?}", id.path().display())) .contents() .into()) } + fn font(&self, index: usize) -> Option { + Some(FONTS.1[index].clone()) + } + fn today(&self, _: Option) -> Option { Some(Datetime::from_ymd(1970, 1, 1).unwrap()) } -- cgit v1.2.3