diff --git a/dev-docs/feature-format-matrix/qmd-files/callout/no-icon.qmd b/dev-docs/feature-format-matrix/qmd-files/callout/no-icon.qmd index 5196b1e5bfb..cf301d231e0 100644 --- a/dev-docs/feature-format-matrix/qmd-files/callout/no-icon.qmd +++ b/dev-docs/feature-format-matrix/qmd-files/callout/no-icon.qmd @@ -1,9 +1,11 @@ --- title: Callout with no icon format: - html: + html: quality: 0 comment: Title is a offset a little too far down + typst: + quality: 1 --- ::: {.callout-note icon="false"} diff --git a/news/changelog-1.9.md b/news/changelog-1.9.md index 5bdd19aee88..ff2ac63e484 100644 --- a/news/changelog-1.9.md +++ b/news/changelog-1.9.md @@ -29,6 +29,7 @@ All changes included in 1.9: - ([#13362](https://github.com/quarto-dev/quarto-cli/issues/13362)): Remove unused `blockquote` definitions from template. - ([#13452](https://github.com/quarto-dev/quarto-cli/issues/13452)): Wraps subfigure captions generated by `quarto_super()` in `block` function to avoid emitting `par` elements. (author: @christopherkenny) - ([#13474](https://github.com/quarto-dev/quarto-cli/issues/13474)): Heading font for title should default to `mainfont`. +- ([#13555](https://github.com/quarto-dev/quarto-cli/issues/13555)): Add support for `icon=false` in callouts when used in `format: typst`. ## Projects diff --git a/src/resources/filters/customnodes/callout.lua b/src/resources/filters/customnodes/callout.lua index 23bba298277..962262c38dd 100644 --- a/src/resources/filters/customnodes/callout.lua +++ b/src/resources/filters/customnodes/callout.lua @@ -276,7 +276,7 @@ function _callout_main() end end if callout.attr.identifier == "" then - return _quarto.format.typst.function_call("callout", { + return _quarto.format.typst.function_call("callout", { { "body", _quarto.format.typst.as_typst_content(callout.content) }, { "title", _quarto.format.typst.as_typst_content( (not quarto.utils.is_empty_node(callout.title) and callout.title) or @@ -284,18 +284,18 @@ function _callout_main() )}, { "background_color", pandoc.RawInline("typst", background_color) }, { "icon_color", pandoc.RawInline("typst", icon_color) }, - { "icon", pandoc.RawInline("typst", "" .. icon .. "()")}, + { "icon", pandoc.RawInline("typst", callout.icon == false and "none" or ("" .. icon .. "()"))}, { "body_background_color", pandoc.RawInline("typst", body_background_color)} }) end - local typst_callout = _quarto.format.typst.function_call("callout", { + local typst_callout = _quarto.format.typst.function_call("callout", { { "body", _quarto.format.typst.as_typst_content(callout.content) }, { "title", _quarto.format.typst.as_typst_content(callout.title, "inlines") }, { "background_color", pandoc.RawInline("typst", background_color) }, { "icon_color", pandoc.RawInline("typst", icon_color) }, - { "icon", pandoc.RawInline("typst", "" .. icon .. "()")}, + { "icon", pandoc.RawInline("typst", callout.icon == false and "none" or ("" .. icon .. "()"))}, { "body_background_color", pandoc.RawInline("typst", body_background_color)} }) diff --git a/src/resources/formats/typst/pandoc/quarto/definitions.typ b/src/resources/formats/typst/pandoc/quarto/definitions.typ index 0991ac33496..fff6dcdc4c1 100644 --- a/src/resources/formats/typst/pandoc/quarto/definitions.typ +++ b/src/resources/formats/typst/pandoc/quarto/definitions.typ @@ -117,7 +117,12 @@ // when we cleanup pandoc's emitted code to avoid spaces this will have to change let old_callout = it.body.children.at(1).body.children.at(1) let old_title_block = old_callout.body.children.at(0) - let old_title = old_title_block.body.body.children.at(2) + let children = old_title_block.body.body.children + let old_title = if children.len() == 1 { + children.at(0) // no icon: title at index 0 + } else { + children.at(1) // with icon: title at index 1 + } // TODO use custom separator if available let new_title = if empty(old_title) { @@ -127,12 +132,14 @@ } let new_title_block = block_with_new_content( - old_title_block, + old_title_block, block_with_new_content( - old_title_block.body, - old_title_block.body.body.children.at(0) + - old_title_block.body.body.children.at(1) + - new_title)) + old_title_block.body, + if children.len() == 1 { + new_title // no icon: just the title + } else { + children.at(0) + new_title // with icon: preserve icon block + new title + })) block_with_new_content(old_callout, block(below: 0pt, new_title_block) + @@ -152,9 +159,9 @@ width: 100%, below: 0pt, block( - fill: background_color, - width: 100%, - inset: 8pt)[#text(icon_color, weight: 900)[#icon] #title]) + + fill: background_color, + width: 100%, + inset: 8pt)[#if icon != none [#text(icon_color, weight: 900)[#icon] ]#title]) + if(body != []){ block( inset: 1pt, diff --git a/tests/docs/smoke-all/typst/callout-no-icon.qmd b/tests/docs/smoke-all/typst/callout-no-icon.qmd new file mode 100644 index 00000000000..778053397b3 --- /dev/null +++ b/tests/docs/smoke-all/typst/callout-no-icon.qmd @@ -0,0 +1,53 @@ +--- +title: Callouts with icon=false +format: typst +keep-typ: true +_quarto: + tests: + typst: + ensureTypstFileRegexMatches: + - + # we do one big regex to be sure to match in order + - '[\s\S]+\#callout\([\s\S]+icon:\s*none[\s\S]+[\s\S]+\#callout\([\s\S]+icon:\s*none[\s\S]+[\s\S]+\#callout\([\s\S]+icon:\s*none[\s\S]+[\s\S]+\#callout\([\s\S]+icon:\s*fa-' +--- + +## Note Callouts with icon=false {#no-icon-notes} + +::: {.callout-note icon="false"} + +## Note without icon + +This is a note callout without an icon. + +::: + +## Warnings Callouts with icon=false {#no-icon-warnings} + +::: {.callout-warning icon=false} + +## Warning without icon + +This is a warning callout without an icon. + +::: + +## Tip Callouts with icon=false {#no-icon-tip} + + +::: {#tip-example .callout-tip icon="false"} + +A tip without a title and without an icon. + +::: + +See @tip-example + +## Regular callout with icon {#with-icon-important} + +::: {.callout-important} + +## Important with icon + +This callout should have an icon (default behavior). + +:::