@@ -141,10 +141,20 @@ local function warn_conversion (expected, actual, shift, extrainfo)
141
141
dbginfostr = (dbginfo .name or ' <no name>' ) .. ' in ' .. dbginfo .source
142
142
.. ' :' .. dbginfo .currentline
143
143
end
144
- error (actual .. ' instead of ' .. expected .. ' : ' .. dbginfostr
144
+ warn (actual .. ' instead of ' .. expected .. ' : ' .. dbginfostr
145
145
.. (extrainfo and ' \n ' .. extrainfo or ' ' ))
146
146
end
147
147
148
+ local makeCaption = pandoc .Caption
149
+ if not makeCaption then
150
+ makeCaption = function (long , short )
151
+ return {
152
+ long = long ,
153
+ short = short
154
+ }
155
+ end
156
+ end
157
+
148
158
local ensure_type
149
159
ensure_type = {
150
160
Attr = function (obj )
@@ -160,42 +170,49 @@ ensure_type = {
160
170
if pt == ' Blocks' then
161
171
return obj
162
172
elseif pt == ' List' or pt == ' table' then
163
- warn_conversion (' Blocks' , pt , shift , extrainfo )
173
+ warn_conversion (' Blocks' , pt , shift , tostring ( obj ) )
164
174
return setmetatable (obj , BlocksMT )
165
175
elseif pt == ' Inline' then
166
- warn_conversion (' Blocks' , pt , shift )
176
+ warn_conversion (' Blocks' , pt , shift , tostring ( obj ) )
167
177
return setmetatable ({pandoc .Plain {obj }}, BlocksMT )
168
178
elseif pt == ' Inlines' then
169
- warn_conversion (' Blocks' , pt , shift )
179
+ warn_conversion (' Blocks' , pt , shift , tostring ( obj ) )
170
180
return setmetatable ({pandoc .Plain (obj )}, BlocksMT )
171
181
else
172
- warn_conversion (' Blocks' , pt , shift )
182
+ warn_conversion (' Blocks' , pt , shift , tostring ( obj ) )
173
183
return pandoc .Blocks (obj )
174
184
end
175
185
end ,
176
186
177
- Caption = function (obj , shift )
187
+ Caption = function (obj , shift , extrainfo )
178
188
local tp = ptype (obj )
179
- if tp == ' table' and obj .long then
180
- obj .long = ensure_type [' Blocks' ](obj .long , shift + 1 )
189
+ if tp == ' Caption' then
190
+ return obj
191
+ elseif tp == ' table' and obj .long then
192
+ if pandoc .Caption then warn_conversion (' Caption' , tp ) end
193
+ local long = ensure_type [' Blocks' ](obj .long , shift + 1 , extrainfo )
194
+ local short
181
195
if obj .short then
182
- obj . short = ensure_type [' Inlines' ](obj .short , shift + 1 )
196
+ short = ensure_type [' Inlines' ](obj .short , shift + 1 , extrainfo )
183
197
end
184
- return obj
198
+ return makeCaption ( long , short )
185
199
else
186
- warn_conversion (' Caption' , tp )
187
- local blocks = ensure_type [' Blocks' ](obj )
188
- for i = 1 , # obj do
189
- obj [i ] = nil
200
+ if pandoc .Caption then warn_conversion (' Caption' , tp ) end
201
+ local blocks = ensure_type [' Blocks' ](obj , shift + 1 , extrainfo )
202
+ if pandoc .Caption then
203
+ return pandoc .Caption (blocks )
204
+ else
205
+ for i = 1 , # obj do
206
+ obj [i ] = nil
207
+ end
208
+ obj .long = blocks
209
+ return obj
190
210
end
191
- obj .long = blocks
192
- return obj
193
211
end
194
212
end ,
195
213
196
214
DefinitionItem = function (obj , shift )
197
215
shift = shift or 0
198
- -- warn_conversion('DefinitionItem', type(obj))
199
216
obj [1 ] = ensure_type [' Inlines' ](obj [1 ], shift + 1 )
200
217
obj [2 ] = ensure_type [{ sequence = ' Blocks' }](obj [2 ], shift + 1 )
201
218
return obj
@@ -279,15 +296,15 @@ ensure_type = {
279
296
280
297
TableFoot = function (obj )
281
298
local pt = ptype (obj )
282
- if pt ~= ' pandoc TableFoot' then
299
+ if pt ~= ' pandoc TableFoot' and pt ~= ' TableFoot ' then
283
300
error (' Cannot auto-convert to TableFoot, got ' .. pt )
284
301
end
285
302
return obj
286
303
end ,
287
304
288
305
TableHead = function (obj )
289
306
local pt = ptype (obj )
290
- if pt ~= ' pandoc TableHead' then
307
+ if pt ~= ' pandoc TableHead' and pt ~= ' TableHead ' then
291
308
error (' Cannot auto-convert to TableHead, got ' .. pt )
292
309
end
293
310
return obj
@@ -329,6 +346,7 @@ local ensure_type_metatable = {
329
346
}
330
347
setmetatable (ensure_type , ensure_type_metatable )
331
348
349
+ local CaptionMT = pandoc .Caption and debug.getmetatable (pandoc .Caption {})
332
350
local CellMT = debug.getmetatable (pandoc .Cell {})
333
351
local InlineMT = debug.getmetatable (pandoc .Space ())
334
352
local BlockMT = debug.getmetatable (pandoc .HorizontalRule ())
@@ -357,6 +375,18 @@ local function enable_attribute_checks()
357
375
end
358
376
end
359
377
378
+ -- Caption (currently only in pandoc dev version)
379
+ if CaptionMT then
380
+ CaptionMT .setters .short = function (obj , key , value )
381
+ if value ~= nil then
382
+ default_setter (obj , key , ensure_type [' Inlines' ](value ))
383
+ end
384
+ end
385
+ CaptionMT .setters .long = function (obj , key , value )
386
+ default_setter (obj , key , ensure_type [' Blocks' ](value ))
387
+ end
388
+ end
389
+
360
390
-- Cell
361
391
CellMT .setters .col_span = function (obj , key , value )
362
392
default_setter (obj , key , ensure_type [' integer' ](value ))
0 commit comments