summaryrefslogtreecommitdiff
path: root/src/model/content.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-17 18:43:20 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-17 18:43:20 +0100
commit59903270dc5a21c65df8a4d88068662287918b4c (patch)
tree0ad087fcaa3ad84efe24cf316549655ea9162430 /src/model/content.rs
parentaf7fe4d76083c597ec2198a73383b9e3899d75ea (diff)
Methods for page and location on queried content
Diffstat (limited to 'src/model/content.rs')
-rw-r--r--src/model/content.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/model/content.rs b/src/model/content.rs
index 5317236e..3c661929 100644
--- a/src/model/content.rs
+++ b/src/model/content.rs
@@ -2,6 +2,7 @@ use std::any::TypeId;
use std::fmt::{self, Debug, Formatter, Write};
use std::hash::{Hash, Hasher};
use std::iter::{self, Sum};
+use std::num::NonZeroUsize;
use std::ops::{Add, AddAssign, Deref};
use ecow::{eco_format, EcoString, EcoVec};
@@ -9,10 +10,10 @@ use once_cell::sync::Lazy;
use super::{
node, Behave, Behaviour, Fold, Guard, Locatable, Recipe, StableId, Style, StyleMap,
- Synthesize,
+ Synthesize, Vt,
};
use crate::diag::{SourceResult, StrResult};
-use crate::doc::Meta;
+use crate::doc::{Location, Meta};
use crate::eval::{
cast_from_value, cast_to_value, Args, Cast, Func, FuncInfo, Str, Value, Vm,
};
@@ -185,6 +186,22 @@ impl Content {
self.field(field).ok_or_else(|| missing_field(field))
}
+ /// Determine the page of this content.
+ pub fn page(&self, vt: &Vt) -> StrResult<NonZeroUsize> {
+ match self.stable_id() {
+ Some(id) => Ok(vt.introspector.page(id)),
+ None => Err("this method can only be called on queried content".into()),
+ }
+ }
+
+ /// Determine the location of this content.
+ pub fn location(&self, vt: &Vt) -> StrResult<Location> {
+ match self.stable_id() {
+ Some(id) => Ok(vt.introspector.location(id)),
+ None => Err("this method can only be called on queried content".into()),
+ }
+ }
+
/// The content's label.
pub fn label(&self) -> Option<&Label> {
match self.field("label")? {