-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabstract.lua
59 lines (54 loc) · 1.6 KB
/
abstract.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- Adopted from https://github.com/quarto-dev/quarto-cli/discussions/2715#discussioncomment-3883630
local List = require("pandoc.List")
local utils = require("pandoc.utils")
local stringify = utils.stringify
local Abstract = nil
local function create_abstract(ab)
Abstract = {}
table.insert(Abstract, pandoc.Header(1, "Abstract"))
table.insert(Abstract, pandoc.Para(utils.stringify(ab))) -- utils.stringify is added
end
local Keywords = nil
local function create_keyword_list(kw)
Keywords = {}
local kws = pandoc.List({})
for i, keyword in ipairs(kw) do
kws:insert(stringify(keyword))
end
local kwentry = table.concat(kws, "; ")
kwentry = "Keywords: " .. kwentry .. "."
table.insert(Keywords, pandoc.Para(pandoc.Str(kwentry)))
end
local function remove_abstract_meta(meta)
meta["abstract"] = nil
meta["keywords"] = nil
return meta
end
return {
{
Meta = function(meta)
if meta["abstract"] ~= nil then
create_abstract(meta["abstract"])
end
if meta["keywords"] ~= nil then
create_keyword_list(meta["keywords"])
end
return meta
end,
},
{
Pandoc = function(doc)
local meta = doc.meta
local body = List:new({})
if Abstract then
body:extend(Abstract)
end
if Keywords then
body:extend(Keywords)
end
body:extend(doc.blocks)
meta = remove_abstract_meta(meta)
return pandoc.Pandoc(body, meta)
end,
},
}