mirror of
https://github.com/typst/typst
synced 2025-08-24 11:44:12 +08:00
Update tests and documentation
This commit is contained in:
parent
d084926ffc
commit
b847a3d3a8
@ -463,13 +463,17 @@ impl Outlinable for Packed<FigureElem> {
|
|||||||
/// customize the appearance of captions for all figures or figures of a
|
/// customize the appearance of captions for all figures or figures of a
|
||||||
/// specific kind.
|
/// specific kind.
|
||||||
///
|
///
|
||||||
/// In addition to its `position` and `body`, the `caption` also provides the
|
/// In addition to its `position` and `body`, it is possible to retrieve the
|
||||||
/// figure's `kind`, `supplement`, `counter`, and `numbering` as fields. These
|
/// corresponding figure's `kind`, `supplement`, `counter`, and `numbering` by
|
||||||
/// parts can be used in [`where`]($function.where) selectors and show rules to
|
/// using the corresponding methods. These parts can be used in show rules to
|
||||||
/// build a completely custom caption.
|
/// build a completely custom caption.
|
||||||
///
|
///
|
||||||
/// ```example
|
/// ```example
|
||||||
/// #show figure.caption: emph
|
/// #show figure.caption: it => [
|
||||||
|
/// #underline(it.body) |
|
||||||
|
/// #it.supplement()
|
||||||
|
/// #context it.counter().display(it.numbering())
|
||||||
|
/// ]
|
||||||
///
|
///
|
||||||
/// #figure(
|
/// #figure(
|
||||||
/// rect[Hello],
|
/// rect[Hello],
|
||||||
@ -522,22 +526,6 @@ pub struct FigureCaption {
|
|||||||
pub separator: Smart<Content>,
|
pub separator: Smart<Content>,
|
||||||
|
|
||||||
/// The caption's body.
|
/// 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]
|
#[required]
|
||||||
pub body: Content,
|
pub body: Content,
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ use typst_macros::scope;
|
|||||||
///
|
///
|
||||||
/// #show ref: it => {
|
/// #show ref: it => {
|
||||||
/// let eq = math.equation
|
/// let eq = math.equation
|
||||||
/// let el = it.element
|
/// let el = it.element()
|
||||||
/// if el != none and el.func() == eq {
|
/// if el != none and el.func() == eq {
|
||||||
/// // Override equation references.
|
/// // Override equation references.
|
||||||
/// link(el.location(),numbering(
|
/// link(el.location(),numbering(
|
||||||
|
@ -58,8 +58,7 @@ $x$$y$
|
|||||||
--- issue-2821-missing-fields ---
|
--- issue-2821-missing-fields ---
|
||||||
// Issue #2821: Setting a figure's supplement to none removes the field
|
// Issue #2821: Setting a figure's supplement to none removes the field
|
||||||
#show figure.caption: it => {
|
#show figure.caption: it => {
|
||||||
assert(it.has("supplement"))
|
assert(it.supplement() == none)
|
||||||
assert(it.supplement == none)
|
|
||||||
}
|
}
|
||||||
#figure([], caption: [], supplement: none)
|
#figure([], caption: [], supplement: none)
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ We can clearly see that @fig-cylinder and
|
|||||||
if not it.numbering == none {
|
if not it.numbering == none {
|
||||||
title = it.supplement
|
title = it.supplement
|
||||||
if not it.numbering == none {
|
if not it.numbering == none {
|
||||||
title += " " + it.counter.display(it.numbering)
|
title += " " + counter(figure.where(kind: it.kind)).display(it.numbering)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
title = strong(title)
|
title = strong(title)
|
||||||
@ -168,7 +168,10 @@ We can clearly see that @fig-cylinder and
|
|||||||
|
|
||||||
--- figure-caption-where-selector ---
|
--- figure-caption-where-selector ---
|
||||||
// Test figure.caption element for specific figure kinds
|
// 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(
|
#figure(
|
||||||
[Not a table],
|
[Not a table],
|
||||||
@ -212,8 +215,8 @@ We can clearly see that @fig-cylinder and
|
|||||||
|
|
||||||
#show figure.caption: it => emph[
|
#show figure.caption: it => emph[
|
||||||
#it.body
|
#it.body
|
||||||
(#it.supplement
|
(#it.supplement()
|
||||||
#context it.counter.display(it.numbering))
|
#context it.counter().display(it.numbering()))
|
||||||
]
|
]
|
||||||
|
|
||||||
#figure(
|
#figure(
|
||||||
|
@ -513,7 +513,7 @@ fn main() {
|
|||||||
|
|
||||||
--- raw-line-alternating-fill ---
|
--- raw-line-alternating-fill ---
|
||||||
#set page(width: 200pt)
|
#set page(width: 200pt)
|
||||||
#show raw: it => stack(dir: ttb, ..it.lines)
|
#show raw: it => stack(dir: ttb, ..it.lines())
|
||||||
#show raw.line: it => {
|
#show raw.line: it => {
|
||||||
box(
|
box(
|
||||||
width: 100%,
|
width: 100%,
|
||||||
@ -564,21 +564,21 @@ print(y)
|
|||||||
// Test line extraction works.
|
// Test line extraction works.
|
||||||
|
|
||||||
#show raw: code => {
|
#show raw: code => {
|
||||||
for i in code.lines {
|
for i in code.lines() {
|
||||||
test(i.count, 10)
|
test(i.count, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
test(code.lines.at(0).text, "import numpy as np")
|
test(code.lines().at(0).text, "import numpy as np")
|
||||||
test(code.lines.at(1).text, "")
|
test(code.lines().at(1).text, "")
|
||||||
test(code.lines.at(2).text, "def f(x):")
|
test(code.lines().at(2).text, "def f(x):")
|
||||||
test(code.lines.at(3).text, " return x**2")
|
test(code.lines().at(3).text, " return x**2")
|
||||||
test(code.lines.at(4).text, "")
|
test(code.lines().at(4).text, "")
|
||||||
test(code.lines.at(5).text, "x = np.linspace(0, 10, 100)")
|
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(6).text, "y = f(x)")
|
||||||
test(code.lines.at(7).text, "")
|
test(code.lines().at(7).text, "")
|
||||||
test(code.lines.at(8).text, "print(x)")
|
test(code.lines().at(8).text, "print(x)")
|
||||||
test(code.lines.at(9).text, "print(y)")
|
test(code.lines().at(9).text, "print(y)")
|
||||||
test(code.lines.at(10, default: none), none)
|
test(code.lines().at(10, default: none), none)
|
||||||
}
|
}
|
||||||
|
|
||||||
```py
|
```py
|
||||||
|
Loading…
x
Reference in New Issue
Block a user