From c566653a645c8317f336043117766745304b7887 Mon Sep 17 00:00:00 2001 From: moxie Date: Mon, 16 Mar 2026 02:21:16 +0200 Subject: refactor: normalize text_extensions at config time --- lua/muwiki/config.lua | 7 +++++++ lua/muwiki/links.lua | 9 ++++----- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'lua') diff --git a/lua/muwiki/config.lua b/lua/muwiki/config.lua index 831e406..362cc26 100644 --- a/lua/muwiki/config.lua +++ b/lua/muwiki/config.lua @@ -23,6 +23,13 @@ function M.setup(opts) for key, value in pairs(opts) do if key == 'dirs' then -- handled above + elseif key == 'text_extensions' then + -- Normalize extensions by stripping leading dots + M.options.text_extensions = {} + for _, ext in ipairs(value) do + local normalized = ext:gsub("^%.", "") + table.insert(M.options.text_extensions, normalized) + end elseif M.options[key] ~= nil then M.options[key] = value end diff --git a/lua/muwiki/links.lua b/lua/muwiki/links.lua index 2972973..2213dae 100644 --- a/lua/muwiki/links.lua +++ b/lua/muwiki/links.lua @@ -13,12 +13,11 @@ local M = {} ---@field cmd string|function Command or function to handle the URL ---@field exts string[]? Optional list of file extensions this handler supports +-- TODO: Support compound extensions like "tar.gz" or "min.js" local function is_text_extension(ext) - local text_exts = config.options.text_extensions or {} - ext = ext:gsub("^%.", "") - for _, text_ext in ipairs(text_exts) do - local normalized = text_ext:gsub("^%.", "") - if normalized == ext then + local target = ext:gsub("^%.", "") + for _, cfg_ext in ipairs(config.options.text_extensions or {}) do + if cfg_ext == target then return true end end -- cgit v1.2.3