diff options
| author | Mathieu David <mathieudavid@mathieudavid.org> | 2023-06-20 18:10:53 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-20 18:10:53 +0200 |
| commit | 57d4b8b75175c2fb169ab24ae683f580bcd42c99 (patch) | |
| tree | 62631079ba46b3e5bb00a9bcccb7e467558a4d25 /library | |
| parent | 53775b5f0711c777637d0b3ddbca5f3efa3ee836 (diff) | |
Expose the formatted page in outline.entry (#1506)
Diffstat (limited to 'library')
| -rw-r--r-- | library/src/meta/outline.rs | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/library/src/meta/outline.rs b/library/src/meta/outline.rs index 78fa8ffa..ee13729c 100644 --- a/library/src/meta/outline.rs +++ b/library/src/meta/outline.rs @@ -209,7 +209,12 @@ impl Show for OutlineElem { let elems = vt.introspector.query(&self.target(styles).0); for elem in &elems { - let Some(entry) = OutlineEntry::from_outlinable(vt, self.span(), elem.clone().into_inner(), self.fill(styles))? else { + let Some(entry) = OutlineEntry::from_outlinable( + vt, + self.span(), + elem.clone().into_inner(), + self.fill(styles), + )? else { continue; }; @@ -409,7 +414,7 @@ cast! { /// ``` /// /// To completely customize an entry's line, you can also build it from scratch -/// by accessing the `level`, `element`, `body`, and `fill` fields on the entry. +/// by accessing the `level`, `element`, `body`, `fill` and `page` fields on the entry. /// /// Display: Outline Entry /// Category: meta @@ -442,13 +447,18 @@ pub struct OutlineEntry { /// precisely as many `-` characters as necessary to fill a particular gap. #[required] pub fill: Option<Content>, + + /// The page number of the element this entry links to, formatted with the + /// numbering set for the referenced page. + #[required] + pub page: Content, } impl OutlineEntry { - /// Generates an OutlineEntry from the given element, if possible - /// (errors if the element does not implement Outlinable). - /// If the element cannot be outlined (e.g. heading with 'outlined: false'), - /// does not generate an entry instance (returns Ok(None)). + /// Generates an OutlineEntry from the given element, if possible (errors if + /// the element does not implement `Outlinable`). If the element should not + /// be outlined (e.g. heading with 'outlined: false'), does not generate an + /// entry instance (returns `Ok(None)`). fn from_outlinable( vt: &mut Vt, span: Span, @@ -463,12 +473,26 @@ impl OutlineEntry { return Ok(None); }; - Ok(Some(Self::new(outlinable.level(), elem, body, fill))) + let location = elem.location().unwrap(); + let page_numbering = vt + .introspector + .page_numbering(location) + .cast::<Option<Numbering>>() + .unwrap() + .unwrap_or_else(|| { + Numbering::Pattern(NumberingPattern::from_str("1").unwrap()) + }); + + let page = Counter::new(CounterKey::Page) + .at(vt, location)? + .display(vt, &page_numbering)?; + + Ok(Some(Self::new(outlinable.level(), elem, body, fill, page))) } } impl Show for OutlineEntry { - fn show(&self, vt: &mut Vt, _: StyleChain) -> SourceResult<Content> { + fn show(&self, _vt: &mut Vt, _: StyleChain) -> SourceResult<Content> { let mut seq = vec![]; let elem = self.element(); @@ -494,21 +518,9 @@ impl Show for OutlineEntry { seq.push(HElem::new(Fr::one().into()).pack()); } - let page_numbering = vt - .introspector - .page_numbering(location) - .cast::<Option<Numbering>>() - .unwrap() - .unwrap_or_else(|| { - Numbering::Pattern(NumberingPattern::from_str("1").unwrap()) - }); - - let page = Counter::new(CounterKey::Page) - .at(vt, location)? - .display(vt, &page_numbering)?; - // Add the page number. - seq.push(page.linked(Destination::Location(location))); + let page = self.page().linked(Destination::Location(location)); + seq.push(page); Ok(Content::sequence(seq)) } |
