blob: 4b320c3382de8cf0f0dd4617c359b5dd0162f182 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
|