wikilinks: add .html more selectively
This commit is contained in:
@@ -3,8 +3,8 @@
|
|||||||
-- Obsidian's wiki linking where possible. It
|
-- Obsidian's wiki linking where possible. It
|
||||||
-- - replaces spaces with hyphens in the uri path and fragment
|
-- - replaces spaces with hyphens in the uri path and fragment
|
||||||
-- - lower-cases the fragment
|
-- - lower-cases the fragment
|
||||||
-- - adds ".html" to the path (preserving any fragment).
|
-- - adds ".html" to the path when appropriate (preserving any fragment).
|
||||||
-- This is needed when the site is rendered locally, though not on hledger.org.
|
-- This is not needed on hledger.org, but makes links work when rendered locally.
|
||||||
-- Limitations: unlike Obsidian wikilinks,
|
-- Limitations: unlike Obsidian wikilinks,
|
||||||
-- - these do not find files across folders - correct path is required
|
-- - these do not find files across folders - correct path is required
|
||||||
-- - these are not aware of file existence - targets should exist
|
-- - these are not aware of file existence - targets should exist
|
||||||
@@ -12,11 +12,15 @@
|
|||||||
function Link(elem)
|
function Link(elem)
|
||||||
if elem.title == "wikilink" then
|
if elem.title == "wikilink" then
|
||||||
t = elem.target .. "#"
|
t = elem.target .. "#"
|
||||||
t = string.gsub(t, " ", "-")
|
t = t:gsub(" ", "-")
|
||||||
-- t = string.gsub(t, "'", "")
|
-- t = t:gsub(t, "'", "")
|
||||||
path, frag = string.match(t, "([^#]*)#([^#]*)")
|
path, frag = t:match("([^#]*)#([^#]*)")
|
||||||
t = path
|
t = path
|
||||||
if string.len(path) > 0 then
|
if path:len() > 0 and not (
|
||||||
|
path:match('%.html$') or
|
||||||
|
path:match('%.%.$') or
|
||||||
|
path:match('/$')
|
||||||
|
) then
|
||||||
t = t .. ".html"
|
t = t .. ".html"
|
||||||
end
|
end
|
||||||
if string.len(frag) > 0 then
|
if string.len(frag) > 0 then
|
||||||
|
|||||||
Reference in New Issue
Block a user