forked from dramforever/easyriscv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.lua
More file actions
62 lines (57 loc) · 1.66 KB
/
filter.lua
File metadata and controls
62 lines (57 loc) · 1.66 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
52
53
54
55
56
57
58
59
60
61
62
-- SPDX-License-Identifier: CC0-1.0 OR 0BSD
terms_map = {}
terms = {}
-- Adds anchor links to headings with IDs.
function Header(el)
if el.level <= 2 and el.identifier ~= '' then
-- an empty link to this header
local anchor_link = pandoc.Link(
{}, -- content
'#' .. el.identifier, -- href
'', -- title
{class = 'anchor-link', ['aria-hidden'] = 'true'} -- attributes
)
el.content:insert(1, anchor_link)
return el
end
end
function Span(el)
if el.attributes.x ~= nil then
local itype = el.attributes.x;
local text = pandoc.text.lower(pandoc.utils.stringify(el.content))
local id = itype .. '-' .. string.gsub(text, ' ', '-')
if terms[itype] == nil then
terms[itype], terms_map[itype] = {}, {}
end
table.insert(terms[itype], id)
terms_map[itype][id] = el.content
return pandoc.Span(pandoc.Emph(el.content), { id = id })
end
end
function Div(el)
if el.attributes.index_of ~= nil then
local itype = el.attributes.index_of
table.sort(terms[itype])
local contents = {}
for _, id in ipairs(terms[itype]) do
local content = terms_map[itype][id]
table.insert(contents, pandoc.Link(content, '#' .. id))
end
return pandoc.BulletList(contents, { class = 'terms-list' })
end
end
function CodeBlock(el)
function html_escape(s)
return string.gsub(s, "[}{\">/<'&]", {
["&"] = "&",
["<"] = "<",
[">"] = ">",
['"'] = """
})
end
if el.classes[1] == "emulator" then
return pandoc.Div(pandoc.RawInline('html', html_escape(el.text)), {
class = "emulator-disabled"
})
end
end