Fix footnote-reference numbering (#4456)

This commit is contained in:
Yip Coekjan 2024-07-02 22:46:25 +08:00 committed by GitHub
parent 728fb7e475
commit 75246f930b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 2 deletions

View File

@ -93,6 +93,15 @@ impl FootnoteElem {
Self::new(FootnoteBody::Reference(label)) Self::new(FootnoteBody::Reference(label))
} }
/// Creates a new footnote referencing the footnote with the specified label,
/// with the other fields from the current footnote cloned.
pub fn into_ref(&self, label: Label) -> Self {
Self {
body: FootnoteBody::Reference(label),
..self.clone()
}
}
/// Tests if this footnote is a reference to another footnote. /// Tests if this footnote is a reference to another footnote.
pub fn is_ref(&self) -> bool { pub fn is_ref(&self) -> bool {
matches!(self.body(), FootnoteBody::Reference(_)) matches!(self.body(), FootnoteBody::Reference(_))

View File

@ -177,8 +177,8 @@ impl Show for Packed<RefElem> {
let elem = elem.at(span)?; let elem = elem.at(span)?;
if elem.func() == FootnoteElem::elem() { if let Some(footnote) = elem.to_packed::<FootnoteElem>() {
return Ok(FootnoteElem::with_label(target).pack().spanned(span)); return Ok(footnote.into_ref(target).pack().spanned(span));
} }
let elem = elem.clone(); let elem = elem.clone();

Binary file not shown.

After

Width:  |  Height:  |  Size: 830 B

View File

@ -187,3 +187,7 @@ B #footnote[b]
#set page(height: 50pt) #set page(height: 50pt)
#footnote[A] #footnote[A]
#footnote[B] #footnote[B]
--- issue-4454-footnote-ref-numbering ---
// Test that footnote references are numbered correctly.
A #footnote(numbering: "*")[B]<fn>, C @fn, D @fn, E @fn.