Update tests and documentation

This commit is contained in:
Malo 2025-05-29 21:12:08 +01:00
parent d084926ffc
commit b847a3d3a8
5 changed files with 30 additions and 40 deletions

View File

@ -463,13 +463,17 @@ impl Outlinable for Packed<FigureElem> {
/// 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<Content>,
/// 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,

View File

@ -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(

View File

@ -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)

View File

@ -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(

View File

@ -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