summaryrefslogtreecommitdiff
path: root/crates/typst-library/src
diff options
context:
space:
mode:
authorSébastien d'Herbais de Thun <sebastien.d.herbais@gmail.com>2023-11-17 10:39:08 +0100
committerGitHub <noreply@github.com>2023-11-17 10:39:08 +0100
commit5aaaacbf472fc71295d4e4a26615d941a4d92a00 (patch)
treee9cfca891564c5d0ea246815c393445695a3372a /crates/typst-library/src
parent624ff5cb7a80945ac2fed7e2ad266214542183f2 (diff)
Allow `elem` synthesized fields to take a default value (#2687)
Diffstat (limited to 'crates/typst-library/src')
-rw-r--r--crates/typst-library/src/meta/figure.rs4
-rw-r--r--crates/typst-library/src/meta/footnote.rs7
-rw-r--r--crates/typst-library/src/meta/outline.rs9
3 files changed, 18 insertions, 2 deletions
diff --git a/crates/typst-library/src/meta/figure.rs b/crates/typst-library/src/meta/figure.rs
index 6124e9d5..8e08b940 100644
--- a/crates/typst-library/src/meta/figure.rs
+++ b/crates/typst-library/src/meta/figure.rs
@@ -484,19 +484,23 @@ pub struct FigureCaption {
/// The figure's supplement.
#[synthesized]
+ #[default(None)]
pub supplement: Option<Content>,
/// How to number the figure.
#[synthesized]
+ #[default(None)]
pub numbering: Option<Numbering>,
/// The counter for the figure.
#[synthesized]
+ #[default(None)]
pub counter: Option<Counter>,
/// The figure's location.
#[internal]
#[synthesized]
+ #[default(None)]
pub figure_location: Option<Location>,
}
diff --git a/crates/typst-library/src/meta/footnote.rs b/crates/typst-library/src/meta/footnote.rs
index 4306f833..c7bed909 100644
--- a/crates/typst-library/src/meta/footnote.rs
+++ b/crates/typst-library/src/meta/footnote.rs
@@ -270,7 +270,12 @@ impl Show for FootnoteEntry {
let default = StyleChain::default();
let numbering = note.numbering(default);
let counter = Counter::of(FootnoteElem::elem());
- let loc = note.location().unwrap();
+ let Some(loc) = note.location() else {
+ bail!(error!(self.span(), "footnote entry must have a location").with_hint(
+ "try using a query or a show rule to customize the footnote instead"
+ ))
+ };
+
let num = counter.at(vt, loc)?.display(vt, numbering)?;
let sup = SuperElem::new(num)
.pack()
diff --git a/crates/typst-library/src/meta/outline.rs b/crates/typst-library/src/meta/outline.rs
index 0cae0de4..b3b97087 100644
--- a/crates/typst-library/src/meta/outline.rs
+++ b/crates/typst-library/src/meta/outline.rs
@@ -489,7 +489,14 @@ impl Show for OutlineEntry {
// In case a user constructs an outline entry with an arbitrary element.
let Some(location) = elem.location() else {
- bail!(self.span(), "cannot outline {}", elem.func().name())
+ if elem.can::<dyn Locatable>() && elem.can::<dyn Outlinable>() {
+ bail!(error!(self.span(), "{} must have a location", elem.func().name())
+ .with_hint(
+ "try using a query or a show rule to customize the outline.entry instead",
+ ))
+ } else {
+ bail!(self.span(), "cannot outline {}", elem.func().name())
+ }
};
// The body text remains overridable.