-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddRefs.lua
More file actions
51 lines (48 loc) · 1.6 KB
/
addRefs.lua
File metadata and controls
51 lines (48 loc) · 1.6 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
41
42
43
44
45
46
47
48
49
50
51
-- For hlf:
-- Make index page (out of pandoc-generated toc)
-- Add refs-block ("other help sections") to each article.
-- requires: meta.refsTemplate and --toc
-- optional: meta.refsLevel
--luacheck: globals Refs meta
local function Pandoc (doc)
meta = doc.meta
if not meta.refsTemplate then
--print("addRefs: no refsTemplate, exiting")
return
end
local insertRefs = require(meta.refsTemplate[1].text)
if not insertRefs then
return
end
-- add Index section
local toc = pandoc.structure.table_of_contents(doc.blocks):walk{Link=function(el)
el.attr = pandoc.Attr() -- remove auto-id's "toc-title"
return el
end}
doc.blocks:insert(pandoc.Header(1, "Index", pandoc.Attr("index", nil, {refsTitle="i"})))
doc.blocks:insert(toc)
--
Refs = pandoc.List{} -- list of linked articles
local refsLevel = meta.refsLevel
refsLevel = not refsLevel and 1 or refsLevel[1] and tonumber(refsLevel[1].text)
doc.blocks:walk { -- for refs pick all Headers with level<=meta.refsLevel (default 1)
Header=function(el)
if el.identifier~="" and not el.classes:includes("noref") then
if refsLevel and refsLevel<el.level then return end
local content, title = el.content
if el.attributes.refsTitle then
title = pandoc.utils.stringify(content)
content = el.attributes.refsTitle
end
Refs:insert(pandoc.Link(content, el.identifier, title))
end
end
}
--
require"sections"(doc.blocks, insertRefs)
return doc
end
return {
{ Pandoc=Pandoc },
{ Div=function(el) return el.content end }, -- HtmlToFarHelp does not support Divs
}