summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYip Coekjan <69834864+Coekjan@users.noreply.github.com>2024-07-02 22:46:25 +0800
committerGitHub <noreply@github.com>2024-07-02 14:46:25 +0000
commit75246f930b9041c206a8a3c87e6db03bfc9111fd (patch)
treeb930396e9587f9177396f47d4aa6711ec6904260
parent728fb7e475d024e7534aec1e47ea9b888671c1b3 (diff)
Fix footnote-reference numbering (#4456)
-rw-r--r--crates/typst/src/model/footnote.rs9
-rw-r--r--crates/typst/src/model/reference.rs4
-rw-r--r--tests/ref/issue-4454-footnote-ref-numbering.pngbin0 -> 830 bytes
-rw-r--r--tests/suite/model/footnote.typ4
4 files changed, 15 insertions, 2 deletions
diff --git a/crates/typst/src/model/footnote.rs b/crates/typst/src/model/footnote.rs
index f8f36eb2..2aeaad1a 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 511ca3d9..8194eec5 100644
--- a/crates/typst/src/model/reference.rs
+++ b/crates/typst/src/model/reference.rs
@@ -177,8 +177,8 @@ impl Show for Packed<RefElem> {
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::<FootnoteElem>() {
+ 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 00000000..0e89dbd9
--- /dev/null
+++ b/tests/ref/issue-4454-footnote-ref-numbering.png
Binary files differ
diff --git a/tests/suite/model/footnote.typ b/tests/suite/model/footnote.typ
index 34450ca4..d72ca25a 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]<fn>, C @fn, D @fn, E @fn.