diff --git a/crates/typst-library/src/model/figure.rs b/crates/typst-library/src/model/figure.rs index 1d3d75fe8..f846f50a2 100644 --- a/crates/typst-library/src/model/figure.rs +++ b/crates/typst-library/src/model/figure.rs @@ -463,13 +463,17 @@ impl Outlinable for Packed { /// customize the appearance of captions for all figures or figures of a /// specific kind. /// -/// In addition to its `position` and `body`, the `caption` also provides the -/// figure's `kind`, `supplement`, `counter`, and `numbering` as fields. These -/// parts can be used in [`where`]($function.where) selectors and show rules to +/// In addition to its `position` and `body`, it is possible to retrieve the +/// corresponding figure's `kind`, `supplement`, `counter`, and `numbering` by +/// using the corresponding methods. These parts can be used in show rules to /// build a completely custom caption. /// /// ```example -/// #show figure.caption: emph +/// #show figure.caption: it => [ +/// #underline(it.body) | +/// #it.supplement() +/// #context it.counter().display(it.numbering()) +/// ] /// /// #figure( /// rect[Hello], @@ -522,22 +526,6 @@ pub struct FigureCaption { pub separator: Smart, /// The caption's body. - /// - /// Can be used alongside `kind`, `supplement`, `counter`, `numbering`, and - /// `location` to completely customize the caption. - /// - /// ```example - /// #show figure.caption: it => [ - /// #underline(it.body) | - /// #it.supplement - /// #context it.counter.display(it.numbering) - /// ] - /// - /// #figure( - /// rect[Hello], - /// caption: [A rectangle], - /// ) - /// ``` #[required] pub body: Content, diff --git a/crates/typst-library/src/model/reference.rs b/crates/typst-library/src/model/reference.rs index 8d7b4510e..71066a9fb 100644 --- a/crates/typst-library/src/model/reference.rs +++ b/crates/typst-library/src/model/reference.rs @@ -92,7 +92,7 @@ use typst_macros::scope; /// /// #show ref: it => { /// let eq = math.equation -/// let el = it.element +/// let el = it.element() /// if el != none and el.func() == eq { /// // Override equation references. /// link(el.location(),numbering( diff --git a/tests/suite/math/interactions.typ b/tests/suite/math/interactions.typ index 209f2f1b5..7cbf184b1 100644 --- a/tests/suite/math/interactions.typ +++ b/tests/suite/math/interactions.typ @@ -58,8 +58,7 @@ $x$$y$ --- issue-2821-missing-fields --- // Issue #2821: Setting a figure's supplement to none removes the field #show figure.caption: it => { - assert(it.has("supplement")) - assert(it.supplement == none) + assert(it.supplement() == none) } #figure([], caption: [], supplement: none) diff --git a/tests/suite/model/figure.typ b/tests/suite/model/figure.typ index 37fb4ecda..8c49bc568 100644 --- a/tests/suite/model/figure.typ +++ b/tests/suite/model/figure.typ @@ -97,7 +97,7 @@ We can clearly see that @fig-cylinder and if not it.numbering == none { title = it.supplement if not it.numbering == none { - title += " " + it.counter.display(it.numbering) + title += " " + counter(figure.where(kind: it.kind)).display(it.numbering) } } title = strong(title) @@ -168,7 +168,10 @@ We can clearly see that @fig-cylinder and --- figure-caption-where-selector --- // Test figure.caption element for specific figure kinds -#show figure.caption.where(kind: table): underline +#show figure.where(kind: table): it => { + show figure.caption: underline + it +} #figure( [Not a table], @@ -212,8 +215,8 @@ We can clearly see that @fig-cylinder and #show figure.caption: it => emph[ #it.body - (#it.supplement - #context it.counter.display(it.numbering)) + (#it.supplement() + #context it.counter().display(it.numbering())) ] #figure( diff --git a/tests/suite/text/raw.typ b/tests/suite/text/raw.typ index a7f58a8d0..b8bdf2ea0 100644 --- a/tests/suite/text/raw.typ +++ b/tests/suite/text/raw.typ @@ -513,7 +513,7 @@ fn main() { --- raw-line-alternating-fill --- #set page(width: 200pt) -#show raw: it => stack(dir: ttb, ..it.lines) +#show raw: it => stack(dir: ttb, ..it.lines()) #show raw.line: it => { box( width: 100%, @@ -564,21 +564,21 @@ print(y) // Test line extraction works. #show raw: code => { - for i in code.lines { + for i in code.lines() { test(i.count, 10) } - test(code.lines.at(0).text, "import numpy as np") - test(code.lines.at(1).text, "") - test(code.lines.at(2).text, "def f(x):") - test(code.lines.at(3).text, " return x**2") - test(code.lines.at(4).text, "") - test(code.lines.at(5).text, "x = np.linspace(0, 10, 100)") - test(code.lines.at(6).text, "y = f(x)") - test(code.lines.at(7).text, "") - test(code.lines.at(8).text, "print(x)") - test(code.lines.at(9).text, "print(y)") - test(code.lines.at(10, default: none), none) + test(code.lines().at(0).text, "import numpy as np") + test(code.lines().at(1).text, "") + test(code.lines().at(2).text, "def f(x):") + test(code.lines().at(3).text, " return x**2") + test(code.lines().at(4).text, "") + test(code.lines().at(5).text, "x = np.linspace(0, 10, 100)") + test(code.lines().at(6).text, "y = f(x)") + test(code.lines().at(7).text, "") + test(code.lines().at(8).text, "print(x)") + test(code.lines().at(9).text, "print(y)") + test(code.lines().at(10, default: none), none) } ```py