From 1e7873752678a0babc2ec9539a8125db1ae713ee Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 30 Nov 2023 13:12:44 -1000 Subject: [PATCH] wikilinks: add .html more selectively --- wikilinks.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/wikilinks.lua b/wikilinks.lua index 8489ef3..693aaa7 100644 --- a/wikilinks.lua +++ b/wikilinks.lua @@ -3,8 +3,8 @@ -- 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 (preserving any fragment). --- This is needed when the site is rendered locally, though not on hledger.org. +-- - 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 @@ -12,11 +12,15 @@ 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 = t:gsub(" ", "-") + -- t = t:gsub(t, "'", "") + path, frag = t:match("([^#]*)#([^#]*)") 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" end if string.len(frag) > 0 then