Skip to content

Commit 03c0fef

Browse files
committed
scrlttr2: ensure compatibility with upcoming pandoc release
1 parent 3057acc commit 03c0fef

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

scrlttr2/scrlttr2.lua

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
-- Ensure unpack also works if pandoc was compiled against Lua 5.1
22
local unpack = unpack or table.unpack
3+
local utils = require 'pandoc.utils'
34
local List = require 'pandoc.List'
4-
local stringify = (require 'pandoc.utils')['stringify']
5+
local stringify = utils.stringify
56

67
--- Set some default options
78
local default = {
@@ -10,14 +11,28 @@ local default = {
1011
address = 'no address given'
1112
}
1213

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+
1328
--- Return a list of inlines representing a call to a latex command.
1429
local function latex_command (command, ...)
1530
local entry = {
1631
pandoc.RawInline('latex', '\\' .. command),
1732
}
1833
for _, arg in ipairs{...} do
1934
entry[#entry + 1] = pandoc.RawInline('latex', '{')
20-
if type(arg) ~= 'table' then
35+
if type(arg) ~= 'Inlines' then
2136
entry[#entry + 1] = pandoc.RawInline('latex', tostring(arg))
2237
else
2338
List.extend(entry, arg)
@@ -31,9 +46,9 @@ end
3146
local function ensure_inlines (val)
3247
if not val or type(val) == 'string' or type(val) == 'boolean' then
3348
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
3752
local res = List:new{}
3853
for i = 1, #val do
3954
res:extend(val[i])
@@ -48,7 +63,7 @@ end
4863

4964
--- Convert the given value to a MetaList
5065
local function ensure_meta_list (val)
51-
if not val or val.t ~= 'MetaList' then
66+
if not val or type(val) ~= 'List' then
5267
return pandoc.MetaList{}
5368
else
5469
return val

0 commit comments

Comments
 (0)