From 7f0b7a28c7686b7b76ccdc1aa2937c6994c006fe Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 11 Mar 2024 12:51:38 +0100 Subject: [PATCH] Fix figure caption separator synthesis (#3621) --- crates/typst/src/model/figure.rs | 10 +++++++++- tests/typ/bugs/3586-figure-caption-separator.typ | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/typ/bugs/3586-figure-caption-separator.typ diff --git a/crates/typst/src/model/figure.rs b/crates/typst/src/model/figure.rs index b5698fac1..1f8c5759a 100644 --- a/crates/typst/src/model/figure.rs +++ b/crates/typst/src/model/figure.rs @@ -437,7 +437,7 @@ impl Outlinable for Packed { /// caption: [A rectangle], /// ) /// ``` -#[elem(name = "caption", Show)] +#[elem(name = "caption", Synthesize, Show)] pub struct FigureCaption { /// The caption's position in the figure. Either `{top}` or `{bottom}`. /// @@ -546,6 +546,14 @@ impl FigureCaption { } } +impl Synthesize for Packed { + fn synthesize(&mut self, _: &mut Engine, styles: StyleChain) -> SourceResult<()> { + let elem = self.as_mut(); + elem.push_separator(Smart::Custom(elem.get_separator(styles))); + Ok(()) + } +} + impl Show for Packed { #[typst_macros::time(name = "figure.caption", span = self.span())] fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult { diff --git a/tests/typ/bugs/3586-figure-caption-separator.typ b/tests/typ/bugs/3586-figure-caption-separator.typ new file mode 100644 index 000000000..ee992c50e --- /dev/null +++ b/tests/typ/bugs/3586-figure-caption-separator.typ @@ -0,0 +1,7 @@ +// Test that figure caption separator is synthesized correctly. +// https://github.com/typst/typst/issues/3586 +// Ref: false + +--- +#show figure.caption: c => test(c.separator, [#": "]) +#figure(table[], caption: [This is a test caption])