Skip to content

Commit 07f55ab

Browse files
authored
Merge pull request #11011 from quarto-dev/bugfix/8179
layout - do not merge code blocks with different classes
2 parents 95a1626 + ab8b264 commit 07f55ab

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed

news/changelog-1.6.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ All changes included in 1.6:
1111

1212
## Lua Filters and extensions
1313

14+
- ([#8179](https://github.com/quarto-dev/quarto-cli/issues/8179)): When merging code cells for complex layouts, do not merge cells with different languages.
1415
- ([#10004](https://github.com/quarto-dev/quarto-cli/issues/10004)): Resolve callout titles, theorem names, and `code-summary` content through `quarto_ast_pipeline()` and `process_shortcodes()`.
1516
- ([#10196](https://github.com/quarto-dev/quarto-cli/issues/10196)): Protect against nil values in `float.caption_long`.
1617
- ([#10328](https://github.com/quarto-dev/quarto-cli/issues/10328)): Interpret subcells as subfloats when subcap count matches subcell count.

src/resources/filters/layout/layout.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,16 @@ function partition_cells(float)
8686
end
8787

8888
local function handle_preamble_codeblock(block)
89-
if block.t == "CodeBlock" and #preamble > 0 and preamble[#preamble].t == "CodeBlock" then
90-
preamble[#preamble].text = preamble[#preamble].text .. "\n" .. block.text
89+
if #preamble == 0 then
90+
preamble:insert(block)
91+
return
92+
end
93+
local last = preamble[#preamble]
94+
if block.t == "CodeBlock" and
95+
last.t == "CodeBlock" and
96+
-- https://pandoc.org/lua-filters.html#pandoc.list:__eq
97+
last.classes == block.classes then
98+
last.text = last.text .. "\n" .. block.text
9199
else
92100
preamble:insert(block)
93101
end
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: "Block layout"
3+
format: html
4+
engine: knitr
5+
keep-md: true
6+
_quarto:
7+
tests:
8+
html:
9+
ensureHtmlElements:
10+
-
11+
- "pre.r"
12+
- "pre.python"
13+
- []
14+
---
15+
16+
17+
18+
19+
# Code chunk block layout
20+
21+
:::: {layout="[48,-4,48]"}
22+
23+
::: {}
24+
25+
### R
26+
27+
28+
29+
::: {.cell}
30+
31+
```{.r .cell-code}
32+
sqrt(2)
33+
```
34+
35+
::: {.cell-output .cell-output-stdout}
36+
37+
```
38+
[1] 1.414214
39+
```
40+
41+
42+
:::
43+
:::
44+
45+
46+
47+
:::
48+
49+
::: {}
50+
51+
### Python
52+
53+
54+
55+
::: {.cell}
56+
57+
```{.python .cell-code}
58+
import math
59+
math.sqrt(2)
60+
```
61+
62+
::: {.cell-output .cell-output-stdout}
63+
64+
```
65+
1.4142135623730951
66+
```
67+
68+
69+
:::
70+
:::
71+
72+
73+
74+
:::
75+
76+
::::

0 commit comments

Comments
 (0)