summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-29 20:08:53 +0200
committerLaurenz <laurmaedje@gmail.com>2023-03-29 20:10:23 +0200
commit72fb155403801216e244ab1df784ccd2a29c54cb (patch)
tree820001268f86d7f9e43d60120db54124241fd62e /src
parent621922bb35657d002b123913dd507e35a178f4c2 (diff)
Link to label
Diffstat (limited to 'src')
-rw-r--r--src/model/introspect.rs14
-rw-r--r--src/model/realize.rs5
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;
}