1
1
-- ipynb.lua
2
2
-- Copyright (C) 2020-2023 Posit Software, PBC
3
3
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
+
4
60
_quarto .ast .add_renderer (" PanelLayout" , function (_ )
5
61
return _quarto .format .isIpynbOutput () and param (" enable-crossref" , true )
6
62
end , function (layout )
7
63
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 )
10
65
end
66
+
11
67
decorate_caption_with_crossref (layout .float )
12
68
13
69
-- empty options by default
@@ -53,23 +109,17 @@ end, function(layout)
53
109
panel_content :insert (pandoc .utils .from_simple_table (panelTable ))
54
110
end
55
111
56
- local result = pandoc .Div ({})
57
-
58
112
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 {}))
60
114
end
61
115
62
116
if layout .preamble then
63
- return pandoc .Blocks ({ layout .preamble , result })
64
- else
65
- return result
117
+ panel_content :insert (1 , layout .preamble )
66
118
end
119
+ return pandoc .Div (panel_content , attr )
67
120
end )
68
121
69
122
-- this should really be "_quarto.format.isEmbedIpynb()" or something like that..
70
123
_quarto .ast .add_renderer (" PanelLayout" , function (_ )
71
124
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