@@ -75,19 +75,66 @@ function render_pandoc3_figure()
75
75
local filter
76
76
filter = function (state )
77
77
state = state or {}
78
+ local function figure_renderer (figure , is_subfig )
79
+ -- this is a figure that is not cross-referenceable
80
+ -- if this ends up in a layout without fig-pos = H, it'll fail
81
+ -- 'H' forces it to not float
82
+ if figure .identifier == " " then
83
+ figure = _quarto .ast .walk (figure , {
84
+ Image = function (image )
85
+ image .attributes [' fig-pos' ] = ' H'
86
+ return image
87
+ end
88
+ })
89
+ end
90
+ local image
91
+ _quarto .ast .walk (figure , {
92
+ Image = function (img )
93
+ image = img
94
+ end
95
+ })
96
+ if image == nil then
97
+ return figure
98
+ end
99
+ if figure .caption .long ~= nil then
100
+ image .caption = quarto .utils .as_inlines (figure .caption .long )
101
+ end
102
+ for k , v in pairs (figure .attributes ) do
103
+ image .attributes [k ] = v
104
+ end
105
+ if is_subfig then
106
+ image .attributes [' quarto-caption-env' ] = ' subcaption'
107
+ end
108
+ image .classes :extend (figure .classes )
109
+ if state .in_column_margin then
110
+ image .classes :insert (" column-margin" )
111
+ end
112
+ return latexImageFigure (image )
113
+ end
114
+ local function float_renderer (float )
115
+ local count = 0
116
+ local new_content = _quarto .ast .walk (float .content , {
117
+ Figure = function (fig )
118
+ count = count + 1
119
+ return figure_renderer (fig , true ), false
120
+ end
121
+ })
122
+ if count > 0 then
123
+ float .content = new_content
124
+ return float , false
125
+ end
126
+ end
78
127
return {
79
128
traverse = " topdown" ,
80
- FloatRefTarget = function (float )
81
- local count = 0
82
- _quarto .ast .walk (float .content , {
83
- Figure = function ()
84
- count = count + 1
129
+ PanelLayout = function (panel )
130
+ panel .rows = _quarto .ast .walk (panel .rows , {
131
+ Figure = function (fig )
132
+ return figure_renderer (fig , true ), false
85
133
end
86
134
})
87
- if count > 0 then
88
- return nil , false
89
- end
135
+ return panel , false
90
136
end ,
137
+ FloatRefTarget = float_renderer ,
91
138
Div = function (div )
92
139
if div .classes :includes (" column-margin" ) then
93
140
local new_state = {}
@@ -102,37 +149,7 @@ function render_pandoc3_figure()
102
149
end
103
150
end ,
104
151
Figure = function (figure )
105
- -- this is a figure that is not cross-referenceable
106
- -- if this ends up in a layout without fig-pos = H, it'll fail
107
- -- 'H' forces it to not float
108
- if figure .identifier == " " then
109
- figure = _quarto .ast .walk (figure , {
110
- Image = function (image )
111
- image .attributes [' fig-pos' ] = ' H'
112
- return image
113
- end
114
- })
115
- end
116
- local image
117
- _quarto .ast .walk (figure , {
118
- Image = function (img )
119
- image = img
120
- end
121
- })
122
- if image == nil then
123
- return figure
124
- end
125
- if figure .caption .long ~= nil then
126
- image .caption = quarto .utils .as_inlines (figure .caption .long )
127
- end
128
- for k , v in pairs (figure .attributes ) do
129
- image .attributes [k ] = v
130
- end
131
- image .classes :extend (figure .classes )
132
- if state .in_column_margin then
133
- image .classes :insert (" column-margin" )
134
- end
135
- return latexImageFigure (image )
152
+ return figure_renderer (figure , false )
136
153
end
137
154
}
138
155
end
0 commit comments