-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfold.lua
More file actions
40 lines (38 loc) · 1.24 KB
/
fold.lua
File metadata and controls
40 lines (38 loc) · 1.24 KB
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
-- Save space wrapping all (except first) sections content inside spoilers
-- Sections with header level > meta.foldLevel (when specified) will be absorbed
local function wrapSection (blocks, startIdx, endIdx)
-- transform headers into plain (but formatted) text
blocks[startIdx] = pandoc.Para {
pandoc.RawInline("markdown", "[u]"),
pandoc.Strong(blocks[startIdx].content),
pandoc.RawInline("markdown","[/u]")
}
blocks[startIdx].content:insert(pandoc.RawInline("markdown", " [spoiler]"))
blocks:insert(endIdx, pandoc.RawBlock("markdown", "[/spoiler]"))
return endIdx+1
end
local first = true
return {
{
Header=function(el)
if first then -- remove redundant first header, as forum topic already has own title
first = false
return {}
end
if el.classes:includes("noref") then --e.g. cfgscript note
return pandoc.HorizontalRule()
end
end
}, { -- add spoilers
Pandoc=function(doc)
local foldLevel = doc.meta.foldLevel
foldLevel = foldLevel and tonumber(foldLevel[1].text)
require"sections"(doc.blocks, wrapSection, function (header)
if foldLevel and header.level>foldLevel then
return "absorb"
end
end)
return doc
end
}
}