fix: public outline entry.inner() function

This commit is contained in:
Tobias Schmitz 2025-07-13 17:46:55 +02:00
parent b5c6f7132b
commit 3c46056599
No known key found for this signature in database
2 changed files with 42 additions and 31 deletions

View File

@ -496,7 +496,7 @@ const OUTLINE_ENTRY_RULE: ShowFn<OutlineEntry> = |elem, engine, styles| {
let close = quotes.double_close; let close = quotes.double_close;
eco_format!("{prefix} {open}{body}{close} {page_str} {page_nr}",) eco_format!("{prefix} {open}{body}{close} {page_str} {page_nr}",)
}; };
let inner = elem.inner(context, span, body, page)?; let inner = elem.build_inner(context, span, body, page)?;
let block = if elem.element.is::<EquationElem>() { let block = if elem.element.is::<EquationElem>() {
let body = prefix.unwrap_or_default() + inner; let body = prefix.unwrap_or_default() + inner;
BlockElem::new() BlockElem::new()

View File

@ -501,6 +501,47 @@ impl OutlineEntry {
/// This includes the body, the fill, and page number. /// This includes the body, the fill, and page number.
#[func(contextual)] #[func(contextual)]
pub fn inner( pub fn inner(
&self,
engine: &mut Engine,
context: Tracked<Context>,
span: Span,
) -> SourceResult<Content> {
let body = self.body().at(span)?;
let page = self.page(engine, context, span)?;
self.build_inner(context, span, body, page)
}
/// The content which is displayed in place of the referred element at its
/// entry in the outline. For a heading, this is its
/// [`body`]($heading.body); for a figure a caption and for equations, it is
/// empty.
#[func]
pub fn body(&self) -> StrResult<Content> {
Ok(self.outlinable()?.body())
}
/// The page number of this entry's element, formatted with the numbering
/// set for the referenced page.
#[func(contextual)]
pub fn page(
&self,
engine: &mut Engine,
context: Tracked<Context>,
span: Span,
) -> SourceResult<Content> {
let loc = self.element_location().at(span)?;
let styles = context.styles().at(span)?;
let numbering = engine
.introspector
.page_numbering(loc)
.cloned()
.unwrap_or_else(|| NumberingPattern::from_str("1").unwrap().into());
Counter::new(CounterKey::Page).display_at_loc(engine, loc, styles, &numbering)
}
}
impl OutlineEntry {
pub fn build_inner(
&self, &self,
context: Tracked<Context>, context: Tracked<Context>,
span: Span, span: Span,
@ -556,36 +597,6 @@ impl OutlineEntry {
Ok(Content::sequence(seq)) Ok(Content::sequence(seq))
} }
/// The content which is displayed in place of the referred element at its
/// entry in the outline. For a heading, this is its
/// [`body`]($heading.body); for a figure a caption and for equations, it is
/// empty.
#[func]
pub fn body(&self) -> StrResult<Content> {
Ok(self.outlinable()?.body())
}
/// The page number of this entry's element, formatted with the numbering
/// set for the referenced page.
#[func(contextual)]
pub fn page(
&self,
engine: &mut Engine,
context: Tracked<Context>,
span: Span,
) -> SourceResult<Content> {
let loc = self.element_location().at(span)?;
let styles = context.styles().at(span)?;
let numbering = engine
.introspector
.page_numbering(loc)
.cloned()
.unwrap_or_else(|| NumberingPattern::from_str("1").unwrap().into());
Counter::new(CounterKey::Page).display_at_loc(engine, loc, styles, &numbering)
}
}
impl OutlineEntry {
fn outlinable(&self) -> StrResult<&dyn Outlinable> { fn outlinable(&self) -> StrResult<&dyn Outlinable> {
self.element self.element
.with::<dyn Outlinable>() .with::<dyn Outlinable>()