1
1
-- Ensure unpack also works if pandoc was compiled against Lua 5.1
2
2
local unpack = unpack or table.unpack
3
+ local utils = require ' pandoc.utils'
3
4
local List = require ' pandoc.List'
4
- local stringify = ( require ' pandoc. utils' )[ ' stringify' ]
5
+ local stringify = utils . stringify
5
6
6
7
--- Set some default options
7
8
local default = {
@@ -10,14 +11,28 @@ local default = {
10
11
address = ' no address given'
11
12
}
12
13
14
+ --- Returns the type of a metadata value.
15
+ --
16
+ -- @param v a metadata value
17
+ -- @treturn string one of `Blocks`, `Inlines`, `List`, `Map`, `string`, `boolean`
18
+ local function metatype (v )
19
+ if PANDOC_VERSION <= ' 2.16.2' then
20
+ local metatag = type (v ) == ' table' and v .t and v .t :gsub (' ^Meta' , ' ' )
21
+ return metatag and metatag ~= ' Map' and metatag or type (v )
22
+ end
23
+ return utils .type (v )
24
+ end
25
+
26
+ local type = metatype
27
+
13
28
--- Return a list of inlines representing a call to a latex command.
14
29
local function latex_command (command , ...)
15
30
local entry = {
16
31
pandoc .RawInline (' latex' , ' \\ ' .. command ),
17
32
}
18
33
for _ , arg in ipairs {... } do
19
34
entry [# entry + 1 ] = pandoc .RawInline (' latex' , ' {' )
20
- if type (arg ) ~= ' table ' then
35
+ if type (arg ) ~= ' Inlines ' then
21
36
entry [# entry + 1 ] = pandoc .RawInline (' latex' , tostring (arg ))
22
37
else
23
38
List .extend (entry , arg )
31
46
local function ensure_inlines (val )
32
47
if not val or type (val ) == ' string' or type (val ) == ' boolean' then
33
48
return pandoc .MetaInlines {pandoc .Str (tostring (val ))}
34
- elseif type (val ) == ' table ' and val . t == ' MetaInlines ' then
35
- return val
36
- elseif type (val ) == ' table ' then
49
+ elseif type (val ) == ' Inlines ' then
50
+ return val
51
+ elseif type (val ) == ' List ' then
37
52
local res = List :new {}
38
53
for i = 1 , # val do
39
54
res :extend (val [i ])
48
63
49
64
--- Convert the given value to a MetaList
50
65
local function ensure_meta_list (val )
51
- if not val or val . t ~= ' MetaList ' then
66
+ if not val or type ( val ) ~= ' List ' then
52
67
return pandoc .MetaList {}
53
68
else
54
69
return val
0 commit comments