From 6ac71eeaf7b68dab07f75bd1a480810481fa9b73 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 17 Jan 2024 21:50:35 +0100 Subject: Add `Page` struct To get rid of the Meta hack where numbering and things like that are stored in the frame. --- crates/typst-docs/src/html.rs | 12 ++++++------ crates/typst-docs/src/lib.rs | 7 ++++--- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'crates/typst-docs') diff --git a/crates/typst-docs/src/html.rs b/crates/typst-docs/src/html.rs index 7481b050..8f6d1366 100644 --- a/crates/typst-docs/src/html.rs +++ b/crates/typst-docs/src/html.rs @@ -388,8 +388,8 @@ fn code_block(resolver: &dyn Resolver, lang: &str, text: &str) -> Html { let world = DocWorld(source); let mut tracer = Tracer::new(); - let mut frames = match typst::compile(&world, &mut tracer) { - Ok(doc) => doc.pages, + let mut document = match typst::compile(&world, &mut tracer) { + Ok(doc) => doc, Err(err) => { let msg = &err[0].message; panic!("while trying to compile:\n{text}:\n\nerror: {msg}"); @@ -397,16 +397,16 @@ fn code_block(resolver: &dyn Resolver, lang: &str, text: &str) -> Html { }; if let Some([x, y, w, h]) = zoom { - frames[0].translate(Point::new(-x, -y)); - *frames[0].size_mut() = Size::new(w, h); + document.pages[0].frame.translate(Point::new(-x, -y)); + *document.pages[0].frame.size_mut() = Size::new(w, h); } if single { - frames.truncate(1); + document.pages.truncate(1); } let hash = typst::util::hash128(text); - resolver.example(hash, highlighted, &frames) + resolver.example(hash, highlighted, &document) } /// Extract an attribute value from an HTML element. diff --git a/crates/typst-docs/src/lib.rs b/crates/typst-docs/src/lib.rs index ad40b987..f2531462 100644 --- a/crates/typst-docs/src/lib.rs +++ b/crates/typst-docs/src/lib.rs @@ -25,9 +25,10 @@ use typst::foundations::{ FOUNDATIONS, }; use typst::introspection::INTROSPECTION; -use typst::layout::{Abs, Frame, Margin, PageElem, LAYOUT}; +use typst::layout::{Abs, Margin, PageElem, LAYOUT}; use typst::loading::DATA_LOADING; use typst::math::MATH; +use typst::model::Document; use typst::model::MODEL; use typst::symbols::SYMBOLS; use typst::text::{Font, FontBook, TEXT}; @@ -97,7 +98,7 @@ pub trait Resolver { fn image(&self, filename: &str, data: &[u8]) -> String; /// Produce HTML for an example. - fn example(&self, hash: u128, source: Option, frames: &[Frame]) -> Html; + fn example(&self, hash: u128, source: Option, document: &Document) -> Html; /// Determine the commits between two tags. fn commits(&self, from: &str, to: &str) -> Vec; @@ -789,7 +790,7 @@ mod tests { None } - fn example(&self, _: u128, _: Option, _: &[Frame]) -> Html { + fn example(&self, _: u128, _: Option, _: &Document) -> Html { Html::new(String::new()) } -- cgit v1.2.3