Skip to content

Commit c822335

Browse files
committed
add panel tabset fix
1 parent e3c7e07 commit c822335

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

‎src/resources/filters/customnodes/panel-tabset.lua‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ _quarto.ast.add_handler({
261261
return render_tabset(node.attr, tabs, bootstrapTabs())
262262
elseif _quarto.format.isHtmlOutput() then
263263
return render_tabset(node.attr, tabs, tabbyTabs())
264+
elseif _quarto.format.isIpynbOutput() then
265+
-- A notebook has no tabs, and its writer makes code cells only of top-level cells, so the tabs'
266+
-- contents go at the top level (not in a Div), each under its tab's title in bold (a heading
267+
-- would add a section to the notebook's outline for each tab)
268+
return render_tabset_with_labels(tabs)
264269
elseif _quarto.format.isLatexOutput() or _quarto.format.isDocxOutput() or _quarto.format.isEpubOutput() or _quarto.format.isJatsOutput() then
265270
return pandoc.Div(render_tabset_with_l4_headings(tabs), node.attr)
266271
else
@@ -334,6 +339,18 @@ local function min(a, b)
334339
end
335340
end
336341

342+
function render_tabset_with_labels(tabs)
343+
local result = pandoc.Blocks{}
344+
for i=1,#tabs do
345+
local tab = tabs[i]
346+
local heading = tab.content[1]
347+
tab.content:remove(1)
348+
result:insert(pandoc.Para{pandoc.Strong(heading.content)})
349+
result:extend(tab.content)
350+
end
351+
return result
352+
end
353+
337354
function render_tabset_with_l4_headings(tabs)
338355
local result = pandoc.List()
339356
for i=1,#tabs do
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: "Code inside a tabset becomes notebook code cells"
3+
format:
4+
ipynb:
5+
execute:
6+
enabled: false
7+
_quarto:
8+
tests:
9+
ipynb:
10+
ensureIpynbCellMatches:
11+
cellType: code
12+
matches:
13+
- 'print\("first tab"\)'
14+
- 'print\("second tab"\)'
15+
- 'print\("outside"\)'
16+
noMatches:
17+
- 'First'
18+
---
19+
20+
```{python}
21+
print("outside")
22+
```
23+
24+
::: {.panel-tabset}
25+
## First
26+
27+
```{python}
28+
print("first tab")
29+
```
30+
31+
## Second
32+
33+
```{python}
34+
print("second tab")
35+
```
36+
:::

0 commit comments

Comments
 (0)