Skip to content

Commit 20c2761

Browse files
authored
Merge pull request #13592 from quarto-dev/typst/callout-id-error
2 parents 3d772cb + 5aa9e94 commit 20c2761

File tree

4 files changed

+83
-3
lines changed

4 files changed

+83
-3
lines changed

news/changelog-1.9.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ All changes included in 1.9:
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`.
3232
- ([#13555](https://github.com/quarto-dev/quarto-cli/issues/13555)): Add support for `icon=false` in callouts when used in `format: typst`.
33+
- ([#13589](https://github.com/quarto-dev/quarto-cli/issues/13589)): Fix callouts with invalid ID prefixes crashing with "attempt to index a nil value". Callouts with unknown reference types now render as non-crossreferenceable callouts with a warning, ignoring the invalid ID.
3334

3435
## Projects
3536

src/resources/filters/customnodes/callout.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,16 @@ function _callout_main()
275275
end
276276
end
277277
end
278-
if callout.attr.identifier == "" then
278+
-- Check if identifier has a valid crossref category
279+
local ref_type = refType(callout.attr.identifier)
280+
local category = ref_type ~= nil and crossref.categories.by_ref_type[ref_type] or nil
281+
282+
-- Warn if identifier was provided but category is invalid
283+
if callout.attr.identifier ~= "" and category == nil then
284+
warn("Callout ID '" .. callout.attr.identifier .. "' has unknown reference type '" .. (ref_type or "none") .. "'. Rendering as regular callout without cross-reference support.")
285+
end
286+
287+
if category == nil then
279288
return _quarto.format.typst.function_call("callout", {
280289
{ "body", _quarto.format.typst.as_typst_content(callout.content) },
281290
{ "title", _quarto.format.typst.as_typst_content(
@@ -298,8 +307,6 @@ function _callout_main()
298307
{ "icon", pandoc.RawInline("typst", callout.icon == false and "none" or ("" .. icon .. "()"))},
299308
{ "body_background_color", pandoc.RawInline("typst", body_background_color)}
300309
})
301-
302-
local category = crossref.categories.by_ref_type[refType(callout.attr.identifier)]
303310
return make_typst_figure {
304311
content = typst_callout,
305312
caption_location = "top",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: "Callout with valid ID prefix"
3+
format:
4+
typst:
5+
keep-typ: true
6+
_quarto:
7+
tests:
8+
typst:
9+
ensureTypstFileRegexMatches:
10+
-
11+
- '#figure\(\[(\r\n?|\n)#block\[(\r\n?|\n)#callout'
12+
- []
13+
printsMessage:
14+
level: INFO
15+
regex: 'WARNING(.*)Callout ID(.*)unknown reference type'
16+
negate: true
17+
noErrors: true
18+
---
19+
20+
## Test callout with valid crossref ID
21+
22+
This tests that callouts with valid ID prefixes (matching known crossref categories)
23+
are properly wrapped in figures for cross-reference support.
24+
25+
::: {#nte-valid .callout-note}
26+
27+
## Note with valid ID
28+
29+
This callout uses `#nte-valid` which has the valid prefix "nte" (for notes).
30+
This should be wrapped in a `figure` for cross-referencing support.
31+
32+
:::
33+
34+
As mentioned in @nte-valid, valid callout IDs should work correctly.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: "Callout with invalid ID prefix (#13589)"
3+
format:
4+
typst:
5+
keep-typ: true
6+
_quarto:
7+
tests:
8+
typst:
9+
ensureTypstFileRegexMatches:
10+
-
11+
# Should render as plain callout with body parameter
12+
- '#callout\(\s*body:'
13+
-
14+
# Should NOT be wrapped in figure+block structure
15+
- '#figure\(\[(\r\n?|\n)#block\[(\r\n?|\n)#callout'
16+
printsMessage:
17+
level: INFO
18+
regex: 'WARNING(.*)Callout ID ''random-id'' has unknown reference type ''random'''
19+
noErrors: true
20+
---
21+
22+
## Test callout with invalid crossref ID
23+
24+
This tests the fix for issue #13589: callouts with invalid ID prefixes
25+
(not matching any known crossref category) should render with a warning
26+
instead of crashing with "attempt to index a nil value".
27+
28+
::: {#random-id .callout-note}
29+
30+
## Note with invalid ID
31+
32+
This callout uses `#random-id` with unknown prefix "random".
33+
34+
Valid prefixes are: fig, tbl, lst, nte, wrn, cau, tip, imp, prf, rem, sol.
35+
36+
Expected behavior: renders as plain callout (no figure wrapping) with warning.
37+
38+
:::

0 commit comments

Comments
 (0)