Skip to content

Commit b7e7613

Browse files
authored
Merge pull request #9944 from quarto-dev/bugfix/9243
Fix: DecoratedCodeBlocks inside FloatRefTargets
2 parents c256518 + 36f9aef commit b7e7613

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed

news/changelog-1.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ All changes included in 1.5:
2222
- ([#8841](https://github.com/quarto-dev/quarto-cli/issues/8841)): Do not parse LaTeX table when crossref label doesn't start with `tbl-`.
2323
- ([#9582](https://github.com/quarto-dev/quarto-cli/issues/9582)): Forward column classes and attributes correctly to floats inside divs with column classes.
2424
- ([#9729](https://github.com/quarto-dev/quarto-cli/issues/9729)): Fix performance issue with Lua pattern matching and multiple capture groups.
25+
- ([#9944](https://github.com/quarto-dev/quarto-cli/issues/9944)): Fix issue with `lst-` crossrefs, `filename` attributes, and syntax highlighting.
2526

2627
## RevealJS Format
2728

src/resources/filters/customnodes/floatreftarget.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,18 @@ end, function(float)
327327
float.content.caption.long = float.caption_long
328328
float.content.attr = pandoc.Attr(float.identifier, float.classes or {}, float.attributes or {})
329329
return float.content
330+
elseif float_type == "lst" then
331+
local handle_code_block = function(codeblock)
332+
codeblock.attr = merge_attrs(codeblock.attr, pandoc.Attr("", float.classes or {}, float.attributes or {}))
333+
return codeblock
334+
end
335+
if float.content.t == "CodeBlock" then
336+
float.content = handle_code_block(float.content)
337+
else
338+
float.content = _quarto.ast.walk(float.content, {
339+
CodeBlock = handle_code_block
340+
})
341+
end
330342
end
331343

332344
local fig_scap = attribute(float, kFigScap, nil)

src/resources/filters/quarto-post/latex.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,19 @@ function render_latex()
289289
return nil, false
290290
end,
291291
})
292+
elseif float.type == "Listing" then
293+
float.content = _quarto.ast.walk(float.content, {
294+
traverse = "topdown",
295+
-- A Listing float with a decoratedcodeblock inside it needs
296+
-- to be deconstructed
297+
DecoratedCodeBlock = function(block)
298+
if block.filename ~= nil then
299+
float.caption_long.content:insert(1, pandoc.Space())
300+
float.caption_long.content:insert(1, pandoc.Code(block.filename))
301+
end
302+
return block.code_block
303+
end
304+
})
292305
end
293306
float.content = _quarto.ast.walk(quarto.utils.as_blocks(float.content), {
294307
PanelLayout = function(panel)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
format: latex
3+
_quarto:
4+
tests:
5+
latex:
6+
ensureFileRegexMatches:
7+
- ["Shaded"]
8+
- ["tcolorbox"]
9+
---
10+
11+
```{#lst-1 .python lst-cap="A caption"}
12+
print("Hello, World!")
13+
```
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
format: latex
3+
_quarto:
4+
tests:
5+
latex:
6+
ensureFileRegexMatches:
7+
- ["Shaded", "foo.py", "bar.py"]
8+
- ["tcolorbox"]
9+
---
10+
11+
::: {#lst-1 filename="foo.py"}
12+
13+
```{.python}
14+
print("Hello, World!")
15+
```
16+
17+
A caption.
18+
19+
:::
20+
21+
::: {#lst-2}
22+
23+
```{.python filename="bar.py"}
24+
print("Hello, World!")
25+
```
26+
27+
Another caption.
28+
29+
:::
30+
31+
32+
::: {#lst-3}
33+
34+
```{.python}
35+
print("Hello, World!")
36+
```
37+
38+
A caption.
39+
40+
:::
41+
42+
43+
See @lst-1, @lst-2, @lst-3.

0 commit comments

Comments
 (0)