mirror of
https://github.com/typst/typst
synced 2025-05-24 05:55:28 +08:00
Add figure separator field (#1791)
This commit is contained in:
parent
976abdfe7d
commit
6275dfd062
@ -359,12 +359,11 @@ impl Outlinable for FigureElem {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let Some(mut caption) =
|
||||
self.caption(StyleChain::default()).map(|caption| caption.body())
|
||||
else {
|
||||
let Some(caption) = self.caption(StyleChain::default()) else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let mut realized = caption.body();
|
||||
if let (
|
||||
Smart::Custom(Some(Supplement::Content(mut supplement))),
|
||||
Some(counter),
|
||||
@ -381,10 +380,12 @@ impl Outlinable for FigureElem {
|
||||
supplement += TextElem::packed('\u{a0}');
|
||||
}
|
||||
|
||||
caption = supplement + numbers + TextElem::packed(": ") + caption;
|
||||
let separator = caption.separator(StyleChain::default());
|
||||
|
||||
realized = supplement + numbers + separator + caption.body();
|
||||
}
|
||||
|
||||
Ok(Some(caption))
|
||||
Ok(Some(realized))
|
||||
}
|
||||
}
|
||||
|
||||
@ -444,6 +445,19 @@ pub struct FigureCaption {
|
||||
})]
|
||||
pub position: VAlign,
|
||||
|
||||
/// The separator which will appear between the number and body.
|
||||
///
|
||||
/// ```example
|
||||
/// #set figure.caption(separator: [ --- ])
|
||||
///
|
||||
/// #figure(
|
||||
/// rect[Hello],
|
||||
/// caption: [A rectangle],
|
||||
/// )
|
||||
/// ```
|
||||
#[default(TextElem::packed(": "))]
|
||||
pub separator: Content,
|
||||
|
||||
/// The caption's body.
|
||||
///
|
||||
/// Can be used alongside `kind`, `supplement`, `counter`, `numbering`, and
|
||||
@ -487,13 +501,14 @@ pub struct FigureCaption {
|
||||
impl Synthesize for FigureCaption {
|
||||
fn synthesize(&mut self, _: &mut Vt, styles: StyleChain) -> SourceResult<()> {
|
||||
self.push_position(self.position(styles));
|
||||
self.push_separator(self.separator(styles));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Show for FigureCaption {
|
||||
#[tracing::instrument(name = "FigureCaption::show", skip_all)]
|
||||
fn show(&self, vt: &mut Vt, _: StyleChain) -> SourceResult<Content> {
|
||||
fn show(&self, vt: &mut Vt, styles: StyleChain) -> SourceResult<Content> {
|
||||
let mut realized = self.body();
|
||||
|
||||
if let (Some(mut supplement), Some(numbering), Some(counter), Some(location)) =
|
||||
@ -503,7 +518,7 @@ impl Show for FigureCaption {
|
||||
if !supplement.is_empty() {
|
||||
supplement += TextElem::packed('\u{a0}');
|
||||
}
|
||||
realized = supplement + numbers + TextElem::packed(": ") + realized;
|
||||
realized = supplement + numbers + self.separator(styles) + realized;
|
||||
}
|
||||
|
||||
Ok(realized)
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 65 KiB |
@ -100,3 +100,12 @@ We can clearly see that @fig-cylinder and
|
||||
#show figure: set block(breakable: true)
|
||||
|
||||
#figure(table[a][b][c][d][e], caption: [A table])
|
||||
|
||||
---
|
||||
// Test custom separator for figure caption
|
||||
#set figure.caption(separator: [ --- ])
|
||||
|
||||
#figure(
|
||||
table(columns: 2)[a][b],
|
||||
caption: [The table with custom separator.],
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user