Skip to content

Commit 3057acc

Browse files
committed
scholarly-metadata: ensure compatibility with upcoming pandoc release
1 parent 6a5c243 commit 3057acc

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

scholarly-metadata/scholarly-metadata.lua

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ THIS SOFTWARE.
1717
]]
1818
local List = require 'pandoc.List'
1919

20+
--- Returns the type of a metadata value.
21+
--
22+
-- @param v a metadata value
23+
-- @treturn string one of `Blocks`, `Inlines`, `List`, `Map`, `string`, `boolean`
24+
local function metatype (v)
25+
if PANDOC_VERSION <= '2.16.2' then
26+
local metatag = type(v) == 'table' and v.t and v.t:gsub('^Meta', '')
27+
return metatag and metatag ~= 'Map' and metatag or type(v)
28+
end
29+
return pandoc.utils.type(v)
30+
end
31+
32+
local type = pandoc.utils.type or metatype
33+
34+
2035
-- Split a string at commas.
2136
local function comma_separated_values(str)
2237
local acc = List:new{}
@@ -28,20 +43,19 @@ end
2843

2944
--- Ensure the return value is a list.
3045
local function ensure_list (val)
31-
if type(val) ~= 'table' then
32-
-- create singleton list (or empty list if val == nil).
33-
return List:new{val}
34-
elseif val.t == 'MetaInlines' then
46+
if type(val) == 'List' then
47+
return val
48+
elseif type(val) == 'Inlines' then
3549
-- check if this is really a comma-separated list
3650
local csv = comma_separated_values(pandoc.utils.stringify(val))
3751
if #csv >= 2 then
3852
return csv
3953
end
4054
return List:new{val}
41-
elseif val.t == 'MetaList' then
55+
elseif type(val) == 'table' and #val > 0 then
4256
return List:new(val)
4357
else
44-
-- MetaBlocks or MetaMap, use as a singleton
58+
-- Anything else, use as a singleton (or empty list if val == nil).
4559
return List:new{val}
4660
end
4761
end
@@ -67,23 +81,23 @@ end
6781
-- (`nil`).
6882
function to_named_object (obj)
6983
local named = {}
70-
if type(obj) ~= 'table' then
84+
if type(obj) == 'Inlines' then
85+
-- Treat inlines as the name
86+
named.name = obj
87+
named.id = pandoc.utils.stringify(obj)
88+
elseif type(obj) ~= 'table' then
7189
-- if the object isn't a table, just use its value as a name.
7290
named.name = pandoc.MetaInlines{pandoc.Str(tostring(obj))}
7391
named.id = tostring(obj)
74-
elseif obj.t == 'MetaInlines' then
75-
-- Treat inlines as the name
76-
named.name = obj
77-
named.id = pandoc.utils.stringify(obj)
7892
elseif obj.name ~= nil then
7993
-- object has name attribute → just create a copy of the object
8094
add_missing_entries(obj, named)
8195
named.id = pandoc.utils.stringify(named.id or named.name)
8296
elseif next(obj) and next(obj, next(obj)) == nil then
83-
-- the entry's key is taken as the name, the value contains the
84-
-- attributes.
97+
-- Single-entry table. The entry's key is taken as the name, the value
98+
-- contains the attributes.
8599
key, attribs = next(obj)
86-
if type(attribs) == "string" or attribs.t == 'MetaInlines' then
100+
if type(attribs) == 'string' or type(attribs) == 'Inlines' then
87101
named.name = attribs
88102
else
89103
add_missing_entries(attribs, named)

0 commit comments

Comments
 (0)