aboutsummaryrefslogtreecommitdiff
path: root/lua/muwiki/links.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/muwiki/links.lua')
-rw-r--r--lua/muwiki/links.lua31
1 files changed, 13 insertions, 18 deletions
diff --git a/lua/muwiki/links.lua b/lua/muwiki/links.lua
index 3302f3b..72bb229 100644
--- a/lua/muwiki/links.lua
+++ b/lua/muwiki/links.lua
@@ -1,7 +1,13 @@
local utils = require('muwiki.utils')
+local config = require('muwiki.config')
local M = {}
+local function is_text_extension(ext)
+ local text_exts = config.options.text_extensions or {}
+ return vim.list_contains(text_exts, ext)
+end
+
local function get_link_type(target)
if target:match('^https?://') then
return 'web'
@@ -57,15 +63,6 @@ function M.get_link()
}
end
-local function get_wiki_root()
- local wiki_root = utils.wiki_root(0)
- if not wiki_root then
- vim.notify('Not in a wiki buffer', vim.log.levels.ERROR)
- return nil
- end
- return wiki_root
-end
-
function M.open_link()
local link = M.get_link()
if not link then
@@ -80,7 +77,12 @@ function M.open_link()
if link.type == 'file' then
local file_path = utils.resolve(link.target, nil)
- vim.system({ 'xdg-open', file_path }, { detach = true })
+ local ext = file_path:match('%.([^%.]+)$')
+ if ext and is_text_extension(ext) then
+ utils.open_in_buffer(file_path)
+ else
+ vim.system({ 'xdg-open', file_path }, { detach = true })
+ end
return
end
@@ -119,14 +121,7 @@ function M.open_with_menu(handlers, link)
local url = link.target
if link.type == 'file' then
- if vim.startswith(url, 'file://') then
- url = utils.resolve(url, nil)
- else
- local wiki_root = get_wiki_root()
- if wiki_root then
- url = utils.resolve(url, wiki_root)
- end
- end
+ url = utils.resolve(url, nil)
end
local handler_names = {}