-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpandoc-filter.lua
36 lines (32 loc) · 1.29 KB
/
pandoc-filter.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
function Link (link)
local absolute_path = link.target:sub(1,1) == '/'
local external_url = not absolute_path and link.target:find("%a+://") == 1
local isInternalSection = link.target:sub(1,1) == '#'
if isInternalSection then
link.target = link.target:lower()
end
-- !!! FIXME: this doesn't work with subdirs, figure out why this was like this at all.
-- If it's not an absolute path, not an external URL, and not a section link, make it absolute.
--if not absolute_path and not external_url and not isInternalSection then
-- link.target = '/' .. link.target
--end
return link
end
function Header(header)
if header.level >= 2 then
local returnHeader = header
returnHeader.attributes['class'] = 'anchorText'
local svg = pandoc.Image('', '/static_files/link.svg')
svg.attributes['class'] = 'anchorImage'
svg.attributes['width'] = '16'
svg.attributes['height'] = '16'
local link = pandoc.Link('', '#' .. returnHeader.identifier)
local linkContents = pandoc.List(link.content)
linkContents:insert(#linkContents + 1, svg)
local content = pandoc.List(returnHeader.content)
content:insert(#content + 1, link)
returnHeader.content = content
return returnHeader
end
return header
end