Skip to content

Commit 76d8d84

Browse files
authored
Merge pull request #8359 from quarto-dev/bugfix/8356
lua, ipynb - fix ipynb float-less layout rendering
2 parents 7642ec8 + 2f20448 commit 76d8d84

File tree

6 files changed

+182
-18
lines changed

6 files changed

+182
-18
lines changed

src/resources/filters/layout/ipynb.lua

+62-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,69 @@
11
-- ipynb.lua
22
-- Copyright (C) 2020-2023 Posit Software, PBC
33

4+
local function render_ipynb_layout_no_float(layout)
5+
-- empty options by default
6+
if not options then
7+
options = {}
8+
end
9+
-- outer panel to contain css and figure panel
10+
local attr = pandoc.Attr(layout.identifier or "", layout.classes or {}, layout.attributes or {})
11+
local panel_content = pandoc.Blocks({})
12+
-- layout
13+
14+
for i, row in ipairs(layout.layout) do
15+
16+
local aligns = row:map(function(cell)
17+
-- get the align
18+
local align = cell.attributes[kLayoutAlign]
19+
return layoutTableAlign(align)
20+
end)
21+
local widths = row:map(function(cell)
22+
-- propagage percents if they are provided
23+
local layoutPercent = horizontalLayoutPercent(cell)
24+
if layoutPercent then
25+
return layoutPercent / 100
26+
else
27+
return 0
28+
end
29+
end)
30+
31+
local cells = pandoc.List()
32+
for _, cell in ipairs(row) do
33+
cells:insert(cell)
34+
end
35+
36+
-- make the table
37+
local panelTable = pandoc.SimpleTable(
38+
pandoc.List(), -- caption
39+
aligns,
40+
widths,
41+
pandoc.List(), -- headers
42+
{ cells }
43+
)
44+
45+
-- add it to the panel
46+
panel_content:insert(pandoc.utils.from_simple_table(panelTable))
47+
end
48+
49+
50+
if layout.float ~= nil and layout.float.caption_long then
51+
panel_content:insert(pandoc.Para(quarto.utils.as_inlines(layout.float.caption_long) or {}))
52+
end
53+
54+
if layout.preamble then
55+
panel_content:insert(1, layout.preamble)
56+
end
57+
return pandoc.Div(panel_content, attr)
58+
end
59+
460
_quarto.ast.add_renderer("PanelLayout", function(_)
561
return _quarto.format.isIpynbOutput() and param("enable-crossref", true)
662
end, function(layout)
763
if layout.float == nil then
8-
fail_and_ask_for_bug_report("Ipynb format can't render layouts without floats")
9-
return pandoc.Div({})
64+
return render_ipynb_layout_no_float(layout)
1065
end
66+
1167
decorate_caption_with_crossref(layout.float)
1268

1369
-- empty options by default
@@ -53,23 +109,17 @@ end, function(layout)
53109
panel_content:insert(pandoc.utils.from_simple_table(panelTable))
54110
end
55111

56-
local result = pandoc.Div({})
57-
58112
if layout.float.caption_long then
59-
result.content:insert(pandoc.Para(quarto.utils.as_inlines(layout.float.caption_long) or {}))
113+
panel_content:insert(pandoc.Para(quarto.utils.as_inlines(layout.float.caption_long) or {}))
60114
end
61115

62116
if layout.preamble then
63-
return pandoc.Blocks({ layout.preamble, result })
64-
else
65-
return result
117+
panel_content:insert(1, layout.preamble)
66118
end
119+
return pandoc.Div(panel_content, attr)
67120
end)
68121

69122
-- this should really be "_quarto.format.isEmbedIpynb()" or something like that..
70123
_quarto.ast.add_renderer("PanelLayout", function(_)
71124
return _quarto.format.isIpynbOutput() and not param("enable-crossref", true)
72-
end, function(float)
73-
internal_error()
74-
return pandoc.Div({})
75-
end)
125+
end, render_ipynb_layout)

0 commit comments

Comments
 (0)