1
0

render double-bracketed wiki links, roughly in Obsidian style

This commit is contained in:
Simon Michael
2023-11-27 23:41:20 -10:00
parent 60f7c63f04
commit 150e08c462
2 changed files with 29 additions and 1 deletions

26
fixwikilinks.lua Normal file
View File

@@ -0,0 +1,26 @@
-- Pandoc's wikilinks_title_after_pipe extension makes a start at linking
-- [[bracketed wiki links]]. This lua filter finishes the job and tries to
-- mimic Obsidian's wiki linking, by
-- - either hyphen-replacing or dropping all problem characters in the uri
-- - adding ".html" to the uri path
-- - preserving the uri fragment if any
-- - lower-casing the uri fragment
function Link(elem)
if elem.title == "wikilink" then
t = elem.target .. "#"
t = string.gsub(t, " ", "-")
t = string.gsub(t, "'", "")
path, frag = string.match(t, "([^#]*)#([^#]*)")
t = path
if string.len(path) > 0 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