Skip to content

Commit f600362

Browse files
authored
Merge pull request #13590 from quarto-dev/typst/callout-customization
2 parents 091f575 + 6faadbf commit f600362

File tree

5 files changed

+77
-14
lines changed

5 files changed

+77
-14
lines changed

dev-docs/feature-format-matrix/qmd-files/callout/no-icon.qmd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
---
22
title: Callout with no icon
33
format:
4-
html:
4+
html:
55
quality: 0
66
comment: Title is a offset a little too far down
7+
typst:
8+
quality: 1
79
---
810

911
::: {.callout-note icon="false"}

news/changelog-1.9.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ All changes included in 1.9:
2929
- ([#13362](https://github.com/quarto-dev/quarto-cli/issues/13362)): Remove unused `blockquote` definitions from template.
3030
- ([#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)
3131
- ([#13474](https://github.com/quarto-dev/quarto-cli/issues/13474)): Heading font for title should default to `mainfont`.
32+
- ([#13555](https://github.com/quarto-dev/quarto-cli/issues/13555)): Add support for `icon=false` in callouts when used in `format: typst`.
3233

3334
## Projects
3435

src/resources/filters/customnodes/callout.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,26 +276,26 @@ function _callout_main()
276276
end
277277
end
278278
if callout.attr.identifier == "" then
279-
return _quarto.format.typst.function_call("callout", {
279+
return _quarto.format.typst.function_call("callout", {
280280
{ "body", _quarto.format.typst.as_typst_content(callout.content) },
281281
{ "title", _quarto.format.typst.as_typst_content(
282282
(not quarto.utils.is_empty_node(callout.title) and callout.title) or
283283
pandoc.Plain(_quarto.modules.callouts.displayName(callout.type))
284284
)},
285285
{ "background_color", pandoc.RawInline("typst", background_color) },
286286
{ "icon_color", pandoc.RawInline("typst", icon_color) },
287-
{ "icon", pandoc.RawInline("typst", "" .. icon .. "()")},
287+
{ "icon", pandoc.RawInline("typst", callout.icon == false and "none" or ("" .. icon .. "()"))},
288288
{ "body_background_color", pandoc.RawInline("typst", body_background_color)}
289289
})
290290
end
291291

292-
local typst_callout = _quarto.format.typst.function_call("callout", {
292+
local typst_callout = _quarto.format.typst.function_call("callout", {
293293
{ "body", _quarto.format.typst.as_typst_content(callout.content) },
294294
{ "title", _quarto.format.typst.as_typst_content(callout.title, "inlines")
295295
},
296296
{ "background_color", pandoc.RawInline("typst", background_color) },
297297
{ "icon_color", pandoc.RawInline("typst", icon_color) },
298-
{ "icon", pandoc.RawInline("typst", "" .. icon .. "()")},
298+
{ "icon", pandoc.RawInline("typst", callout.icon == false and "none" or ("" .. icon .. "()"))},
299299
{ "body_background_color", pandoc.RawInline("typst", body_background_color)}
300300
})
301301

src/resources/formats/typst/pandoc/quarto/definitions.typ

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@
117117
// when we cleanup pandoc's emitted code to avoid spaces this will have to change
118118
let old_callout = it.body.children.at(1).body.children.at(1)
119119
let old_title_block = old_callout.body.children.at(0)
120-
let old_title = old_title_block.body.body.children.at(2)
120+
let children = old_title_block.body.body.children
121+
let old_title = if children.len() == 1 {
122+
children.at(0) // no icon: title at index 0
123+
} else {
124+
children.at(1) // with icon: title at index 1
125+
}
121126

122127
// TODO use custom separator if available
123128
let new_title = if empty(old_title) {
@@ -127,12 +132,14 @@
127132
}
128133

129134
let new_title_block = block_with_new_content(
130-
old_title_block,
135+
old_title_block,
131136
block_with_new_content(
132-
old_title_block.body,
133-
old_title_block.body.body.children.at(0) +
134-
old_title_block.body.body.children.at(1) +
135-
new_title))
137+
old_title_block.body,
138+
if children.len() == 1 {
139+
new_title // no icon: just the title
140+
} else {
141+
children.at(0) + new_title // with icon: preserve icon block + new title
142+
}))
136143

137144
block_with_new_content(old_callout,
138145
block(below: 0pt, new_title_block) +
@@ -152,9 +159,9 @@
152159
width: 100%,
153160
below: 0pt,
154161
block(
155-
fill: background_color,
156-
width: 100%,
157-
inset: 8pt)[#text(icon_color, weight: 900)[#icon] #title]) +
162+
fill: background_color,
163+
width: 100%,
164+
inset: 8pt)[#if icon != none [#text(icon_color, weight: 900)[#icon] ]#title]) +
158165
if(body != []){
159166
block(
160167
inset: 1pt,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: Callouts with icon=false
3+
format: typst
4+
keep-typ: true
5+
_quarto:
6+
tests:
7+
typst:
8+
ensureTypstFileRegexMatches:
9+
-
10+
# we do one big regex to be sure to match in order
11+
- '<no-icon-notes>[\s\S]+\#callout\([\s\S]+icon:\s*none[\s\S]+<no-icon-warnings>[\s\S]+\#callout\([\s\S]+icon:\s*none[\s\S]+<no-icon-tip>[\s\S]+\#callout\([\s\S]+icon:\s*none[\s\S]+<with-icon-important>[\s\S]+\#callout\([\s\S]+icon:\s*fa-'
12+
---
13+
14+
## Note Callouts with icon=false {#no-icon-notes}
15+
16+
::: {.callout-note icon="false"}
17+
18+
## Note without icon
19+
20+
This is a note callout without an icon.
21+
22+
:::
23+
24+
## Warnings Callouts with icon=false {#no-icon-warnings}
25+
26+
::: {.callout-warning icon=false}
27+
28+
## Warning without icon
29+
30+
This is a warning callout without an icon.
31+
32+
:::
33+
34+
## Tip Callouts with icon=false {#no-icon-tip}
35+
36+
37+
::: {#tip-example .callout-tip icon="false"}
38+
39+
A tip without a title and without an icon.
40+
41+
:::
42+
43+
See @tip-example
44+
45+
## Regular callout with icon {#with-icon-important}
46+
47+
::: {.callout-important}
48+
49+
## Important with icon
50+
51+
This callout should have an icon (default behavior).
52+
53+
:::

0 commit comments

Comments
 (0)