summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorDmitrij <dimabradima@gmail.com>2023-09-12 16:01:59 +0300
committerGitHub <noreply@github.com>2023-09-12 15:01:59 +0200
commit6275dfd062ca4c519b908ed56feb219879116265 (patch)
tree54dd3356ecf245580ddd494d3d43377a3459bb6c /crates
parent976abdfe7dc08ae42ee87e5c2d4ff46ebe172dd1 (diff)
Add figure separator field (#1791)
Diffstat (limited to 'crates')
-rw-r--r--crates/typst-library/src/meta/figure.rs29
1 files changed, 22 insertions, 7 deletions
diff --git a/crates/typst-library/src/meta/figure.rs b/crates/typst-library/src/meta/figure.rs
index 4aebdda6..bab7790a 100644
--- a/crates/typst-library/src/meta/figure.rs
+++ b/crates/typst-library/src/meta/figure.rs
@@ -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)