ghwikipp: pandoc-filter: Drop .md and .mediawiki from links when generating HTML.

From a17dc58165ca83338f1e66f05ba82be3e61f4295 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 6 May 2025 01:01:02 -0400
Subject: [PATCH] pandoc-filter: Drop .md and .mediawiki from links when
 generating HTML.

---
 pandoc-filter-offline.lua | 5 +++++
 pandoc-filter.lua         | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/pandoc-filter-offline.lua b/pandoc-filter-offline.lua
index cb4d468..ca4e29a 100644
--- a/pandoc-filter-offline.lua
+++ b/pandoc-filter-offline.lua
@@ -1,4 +1,9 @@
 function Link (link)
+  -- drop any Markdown or MediaWiki file extensions that might have snuck in.
+  link.target = string.gsub(link.target, '%.md$', '')
+  link.target = string.gsub(link.target, '%.mediawiki$', '')
+
+  -- Add HTML file extension.
   link.target = link.target .. '.html'
   return link
 end
diff --git a/pandoc-filter.lua b/pandoc-filter.lua
index fede84a..97c8a8f 100644
--- a/pandoc-filter.lua
+++ b/pandoc-filter.lua
@@ -5,6 +5,11 @@ function Link (link)
   if isInternalSection then
     link.target = link.target:lower()
   end
+
+  -- drop any Markdown or MediaWiki file extensions that might have snuck in.
+  link.target = string.gsub(link.target, '%.md$', '')
+  link.target = string.gsub(link.target, '%.mediawiki$', '')
+
   -- !!! FIXME: this doesn't work with subdirs, figure out why this was like this at all.
   -- If it's not an absolute path, not an external URL, and not a section link, make it absolute.
   --if not absolute_path and not external_url and not isInternalSection then