-
Notifications
You must be signed in to change notification settings - Fork 0
/
resumen-to-meta.lua
59 lines (54 loc) · 1.54 KB
/
resumen-to-meta.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
--[[
abstract-to-meta – move an "abstract" section into document metadata
Copyright: © 2017–2021 Albert Krewinkel
License: MIT – see LICENSE file for details
]]
local abstract = {}
--- Extract abstract from a list of blocks.
function abstract_from_blocklist (blocks)
local body_blocks = {}
local looking_at_abstract = false
for _, block in ipairs(blocks) do
if block.t == 'Header' and block.level == 1 then
if block.identifier == 'resumen' then
looking_at_abstract = true
else
looking_at_abstract = false
body_blocks[#body_blocks + 1] = block
end
elseif looking_at_abstract then
if block.t == 'HorizontalRule' then
looking_at_abstract = false
else
abstract[#abstract + 1] = block
end
else
body_blocks[#body_blocks + 1] = block
end
end
return body_blocks
end
if PANDOC_VERSION >= {2,9,2} then
-- Check all block lists with pandoc 2.9.2 or later
return {{
Blocks = abstract_from_blocklist,
Meta = function (meta)
if not meta.resumen and #abstract > 0 then
meta.resumen = pandoc.MetaBlocks(abstract)
end
return meta
end
}}
else
-- otherwise, just check the top-level block-list
return {{
Pandoc = function (doc)
local meta = doc.meta
local other_blocks = abstract_from_blocklist(doc.blocks)
if not meta.resumen and #abstract > 0 then
meta.resumen = pandoc.MetaBlocks(abstract)
end
return pandoc.Pandoc(other_blocks, meta)
end,
}}
end