diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/model/introspect.rs | 14 | ||||
| -rw-r--r-- | src/model/realize.rs | 5 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/model/introspect.rs b/src/model/introspect.rs index f0ff1169..31786d5b 100644 --- a/src/model/introspect.rs +++ b/src/model/introspect.rs @@ -3,9 +3,11 @@ use std::hash::Hash; use std::num::NonZeroUsize; use super::{Content, Selector}; +use crate::diag::StrResult; use crate::doc::{Frame, FrameItem, Meta, Position}; use crate::eval::cast_from_value; use crate::geom::{Point, Transform}; +use crate::model::Label; use crate::util::NonZeroExt; /// Stably identifies an element in the document across multiple layout passes. @@ -160,6 +162,18 @@ impl Introspector { .collect() } + /// Query for a unique element with the label. + pub fn query_label(&self, label: &Label) -> StrResult<Content> { + let mut found = None; + for elem in self.all().filter(|elem| elem.label() == Some(label)) { + if found.is_some() { + return Err("label occurs multiple times in the document".into()); + } + found = Some(elem.clone()); + } + found.ok_or_else(|| "label does not exist in the document".into()) + } + /// The total number pages. pub fn pages(&self) -> NonZeroUsize { NonZeroUsize::new(self.pages).unwrap_or(NonZeroUsize::ONE) diff --git a/src/model/realize.rs b/src/model/realize.rs index 10e1b0e2..e96e0dc1 100644 --- a/src/model/realize.rs +++ b/src/model/realize.rs @@ -176,9 +176,8 @@ pub trait Show { /// Post-process an element after it was realized. pub trait Finalize { - /// Finalize the fully realized form of the element. Use this for effects that - /// should work even in the face of a user-defined show rule, for example - /// the linking behaviour of a link element. + /// Finalize the fully realized form of the element. Use this for effects + /// that should work even in the face of a user-defined show rule. fn finalize(&self, realized: Content, styles: StyleChain) -> Content; } |
