summaryrefslogtreecommitdiff
path: root/library/src/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-26 23:42:40 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-26 23:52:01 +0100
commit6bafc6391061d4b589dea835705a08b25a4df9f8 (patch)
tree4add85f17fc56da341acfb58a223ea20d80c280a /library/src/layout
parent0579fd4409375aaa9fd8e87a06fd59097b5fcd97 (diff)
Document metadata
Diffstat (limited to 'library/src/layout')
-rw-r--r--library/src/layout/mod.rs37
1 files changed, 27 insertions, 10 deletions
diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs
index 100e0611..e63a072e 100644
--- a/library/src/layout/mod.rs
+++ b/library/src/layout/mod.rs
@@ -29,7 +29,7 @@ use std::mem;
use comemo::Tracked;
use typed_arena::Arena;
use typst::diag::SourceResult;
-use typst::frame::Frame;
+use typst::doc::Frame;
use typst::geom::*;
use typst::model::{
applicable, capability, realize, Content, Node, SequenceNode, Style, StyleChain,
@@ -40,7 +40,7 @@ use typst::World;
use crate::prelude::*;
use crate::shared::BehavedBuilder;
use crate::structure::{
- DescNode, DocNode, EnumNode, ListItem, ListNode, DESC, ENUM, LIST,
+ DescNode, DocumentNode, EnumNode, ListItem, ListNode, DESC, ENUM, LIST,
};
use crate::text::{
LinebreakNode, ParNode, ParbreakNode, SmartQuoteNode, SpaceNode, TextNode,
@@ -54,7 +54,7 @@ pub trait LayoutRoot {
&self,
world: Tracked<dyn World>,
styles: StyleChain,
- ) -> SourceResult<Vec<Frame>>;
+ ) -> SourceResult<Document>;
}
impl LayoutRoot for Content {
@@ -63,7 +63,7 @@ impl LayoutRoot for Content {
&self,
world: Tracked<dyn World>,
styles: StyleChain,
- ) -> SourceResult<Vec<Frame>> {
+ ) -> SourceResult<Document> {
let scratch = Scratch::default();
let (realized, styles) = realize_root(world, &scratch, self, styles)?;
realized.with::<dyn LayoutRoot>().unwrap().layout_root(world, styles)
@@ -245,7 +245,7 @@ fn realize_root<'a>(
builder.accept(content, styles)?;
builder.interrupt_page(Some(styles))?;
let (pages, shared) = builder.doc.unwrap().pages.finish();
- Ok((DocNode(pages).pack(), shared))
+ Ok((DocumentNode(pages).pack(), shared))
}
/// Realize into a node that is capable of block-level layout.
@@ -357,6 +357,10 @@ impl<'a> Builder<'a> {
}
}
+ if let Some(span) = content.span() {
+ bail!(span, "not allowed here");
+ }
+
Ok(())
}
@@ -378,13 +382,26 @@ impl<'a> Builder<'a> {
map: &StyleMap,
styles: Option<StyleChain<'a>>,
) -> SourceResult<()> {
- if map.interrupts::<PageNode>() {
+ if let Some(Some(span)) = map.interruption::<DocumentNode>() {
+ if self.doc.is_none() {
+ bail!(span, "not allowed here");
+ }
+ if !self.flow.0.is_empty()
+ || !self.par.0.is_empty()
+ || !self.list.items.is_empty()
+ {
+ bail!(span, "must appear before any content");
+ }
+ } else if let Some(Some(span)) = map.interruption::<PageNode>() {
+ if self.doc.is_none() {
+ bail!(span, "not allowed here");
+ }
self.interrupt_page(styles)?;
- } else if map.interrupts::<ParNode>() {
+ } else if map.interruption::<ParNode>().is_some() {
self.interrupt_par()?;
- } else if map.interrupts::<ListNode>()
- || map.interrupts::<EnumNode>()
- || map.interrupts::<DescNode>()
+ } else if map.interruption::<ListNode>().is_some()
+ || map.interruption::<EnumNode>().is_some()
+ || map.interruption::<DescNode>().is_some()
{
self.interrupt_list()?;
}