-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathadd_anchor.lua
More file actions
21 lines (20 loc) · 796 Bytes
/
add_anchor.lua
File metadata and controls
21 lines (20 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-- Define the Lua filter function
function HeaderWithAnchor(elem)
if elem.t == "Header" then
local level = elem.level
if level == 2 or level == 3 then
local anchor_name = elem.attr.identifier
local anchor_tag = pandoc.Link(elem.content, "#" .. anchor_name)
local header_text = elem.content
if level == 2 then
return pandoc.Div({pandoc.RawBlock("html", "<h2 id='".. anchor_name .. "'><a href='#" .. anchor_name .. "'>"), header_text, pandoc.RawBlock("html", "</a></h2>")})
else
return pandoc.Div({pandoc.RawBlock("html", "<h3 id='".. anchor_name .. "'><a href='#" .. anchor_name .. "'>"), header_text, pandoc.RawBlock("html", "</a></h3>")})
end
end
end
end
-- Add the filter to pandoc
return {
{Header = HeaderWithAnchor}
}