summaryrefslogtreecommitdiff
path: root/docs/src/html.rs
diff options
context:
space:
mode:
Diffstat (limited to 'docs/src/html.rs')
-rw-r--r--docs/src/html.rs42
1 files changed, 20 insertions, 22 deletions
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!("<pre>{}</pre>", 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<SourceId> {
- unimplemented!()
- }
-
- fn source(&self, id: SourceId) -> &Source {
- assert_eq!(id.as_u16(), 0, "invalid source id");
- &self.0
- }
-
fn book(&self) -> &Prehashed<FontBook> {
&FONTS.0
}
- fn font(&self, id: usize) -> Option<Font> {
- Some(FONTS.1[id].clone())
+ fn main(&self) -> Source {
+ self.0.clone()
+ }
+
+ fn source(&self, _: FileId) -> FileResult<Source> {
+ Ok(self.0.clone())
}
- fn file(&self, path: &Path) -> FileResult<Buffer> {
+ fn file(&self, id: FileId) -> FileResult<Bytes> {
+ 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<Font> {
+ Some(FONTS.1[index].clone())
+ }
+
fn today(&self, _: Option<i64>) -> Option<Datetime> {
Some(Datetime::from_ymd(1970, 1, 1).unwrap())
}