From 75246f930b9041c206a8a3c87e6db03bfc9111fd Mon Sep 17 00:00:00 2001 From: Yip Coekjan <69834864+Coekjan@users.noreply.github.com> Date: Tue, 2 Jul 2024 22:46:25 +0800 Subject: [PATCH] Fix footnote-reference numbering (#4456) --- crates/typst/src/model/footnote.rs | 9 +++++++++ crates/typst/src/model/reference.rs | 4 ++-- tests/ref/issue-4454-footnote-ref-numbering.png | Bin 0 -> 830 bytes tests/suite/model/footnote.typ | 4 ++++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 tests/ref/issue-4454-footnote-ref-numbering.png diff --git a/crates/typst/src/model/footnote.rs b/crates/typst/src/model/footnote.rs index f8f36eb23..2aeaad1a7 100644 --- a/crates/typst/src/model/footnote.rs +++ b/crates/typst/src/model/footnote.rs @@ -93,6 +93,15 @@ impl FootnoteElem { 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. pub fn is_ref(&self) -> bool { matches!(self.body(), FootnoteBody::Reference(_)) diff --git a/crates/typst/src/model/reference.rs b/crates/typst/src/model/reference.rs index 511ca3d9a..8194eec53 100644 --- a/crates/typst/src/model/reference.rs +++ b/crates/typst/src/model/reference.rs @@ -177,8 +177,8 @@ impl Show for Packed { let elem = elem.at(span)?; - if elem.func() == FootnoteElem::elem() { - return Ok(FootnoteElem::with_label(target).pack().spanned(span)); + if let Some(footnote) = elem.to_packed::() { + return Ok(footnote.into_ref(target).pack().spanned(span)); } let elem = elem.clone(); diff --git a/tests/ref/issue-4454-footnote-ref-numbering.png b/tests/ref/issue-4454-footnote-ref-numbering.png new file mode 100644 index 0000000000000000000000000000000000000000..0e89dbd918d21580cc3593b6f3626009409ae1a4 GIT binary patch literal 830 zcmV-E1Ht@>P)_{rvp=`}_R+`}_L(`}+F&`T6?!`T6+x`1kku_xJbq_V)Gl_4M@g^Yixd^78TV z@$m5S@bK{N@AL2P@9XR9>gw$3>g($2>gnm}=I8C_=jY|+=H=z(f z$jHaX$HvCS#l^+M#KgnH!@|PC!NI}4zP`P^y}Z1r=+B$qN1Xqp`oClpq`$doSdASo12=NnwgoIn3$NCmzS27mXni{ zl9G~0004PNkl1VE8V)Btm@1I$5rMYMxDB_ZIY#5eNX3`z-@kO533 zm15zpu)HG6hXz6^cyaW$+4kkI-}*gl3dX`YP!#bC=Nto?sFKoB0|0%r2HDdrH3;Uh z8F_atY#G747h`Oe(z-@)vF#~G-^r3BRbPXtcdsw1@+IPJ0*u~W^J*2?y3qm?r;fF= zGD#Yp1Yb47h_iq=X>;PE69nN0u7vP=auX7V`A_n!Su->J8Av+C04&a`TO^&DsHg1O zb0nQarK!N)WkE{9cDO952s?cZ7cD8cae8M*YnFK4f*|}=ANQ<8d|bF*{r~^~07*qo IM6N<$f*;(?TmS$7 literal 0 HcmV?d00001 diff --git a/tests/suite/model/footnote.typ b/tests/suite/model/footnote.typ index 34450ca4c..d72ca25a0 100644 --- a/tests/suite/model/footnote.typ +++ b/tests/suite/model/footnote.typ @@ -187,3 +187,7 @@ B #footnote[b] #set page(height: 50pt) #footnote[A] #footnote[B] + +--- issue-4454-footnote-ref-numbering --- +// Test that footnote references are numbered correctly. +A #footnote(numbering: "*")[B], C @fn, D @fn, E @fn.