diff options
| author | moxie <moxie@3kgcat.fi> | 2026-03-13 09:58:53 +0200 |
|---|---|---|
| committer | moxie <moxie@3kgcat.fi> | 2026-03-13 09:58:53 +0200 |
| commit | bc2944651f4dabc68d7f34c796400d80ba132016 (patch) | |
| tree | 3655716442a24ccb758983f0ddc89222916f64c1 /lua/muwiki/handlers.lua | |
chore: init
Diffstat (limited to 'lua/muwiki/handlers.lua')
| -rw-r--r-- | lua/muwiki/handlers.lua | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lua/muwiki/handlers.lua b/lua/muwiki/handlers.lua new file mode 100644 index 0000000..4b320c3 --- /dev/null +++ b/lua/muwiki/handlers.lua @@ -0,0 +1,44 @@ +local config = require('muwiki.config') + + +local M = {} + + +function M.execute(handler, url) + if type(handler.cmd) == 'function' then + handler.cmd(url) + else + vim.system({ handler.cmd, url }, { detach = true }) + end +end + +function M.matches(handler, url) + local pattern = handler.pattern + + if pattern == nil then + return true + end + + if type(pattern) == 'string' then + return url:match(pattern) ~= nil + end + + for _, p in ipairs(pattern) do + if url:match(p) then + return true + end + end + return false +end + +function M.get_matching(url) + local matching = {} + for _, handler in ipairs(config.options.external_handlers) do + if M.matches(handler, url) then + table.insert(matching, handler) + end + end + return matching +end + +return M |
