-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkify.lua
More file actions
26 lines (24 loc) · 793 Bytes
/
Copy pathlinkify.lua
File metadata and controls
26 lines (24 loc) · 793 Bytes
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
-- Add links to keywords
-- Link URLs are stored in the metadata as a `links` dictionary
local pandoc = require 'pandoc'
function Pandoc(doc)
local links = doc.meta.links
if type(links) == "table" then
local add_links = {
traverse = 'topdown',
Link = function(el)
return el, false -- skip processing already existing lnks
end,
Str = function(el)
for key, url in pairs(links) do
if el.text:match(key) then
return pandoc.Link(el, url[1].text), false -- don't process inserted Links
end
end
return el
end
}
doc.blocks = doc.blocks:walk(add_links)
end
return doc
end