1
0
Files
plaintextaccounting/wikilinks.lua
2023-11-30 13:12:44 -10:00

34 lines
1.1 KiB
Lua

-- Pandoc's wikilinks_title_after_pipe extension does basic hyperlinking
-- of [[bracketed wiki links]]. This lua filter does the rest, mimicking
-- Obsidian's wiki linking where possible. It
-- - replaces spaces with hyphens in the uri path and fragment
-- - lower-cases the fragment
-- - adds ".html" to the path when appropriate (preserving any fragment).
-- This is not needed on hledger.org, but makes links work when rendered locally.
-- Limitations: unlike Obsidian wikilinks,
-- - these do not find files across folders - correct path is required
-- - these are not aware of file existence - targets should exist
function Link(elem)
if elem.title == "wikilink" then
t = elem.target .. "#"
t = t:gsub(" ", "-")
-- t = t:gsub(t, "'", "")
path, frag = t:match("([^#]*)#([^#]*)")
t = path
if path:len() > 0 and not (
path:match('%.html$') or
path:match('%.%.$') or
path:match('/$')
) then
t = t .. ".html"
end
if string.len(frag) > 0 then
frag = pandoc.text.lower(frag)
t = t .. "#" .. frag
end
elem.target = t
end
return elem
end