diff options
| author | moxie <moxie@3kgcat.fi> | 2026-03-15 14:17:01 +0200 |
|---|---|---|
| committer | moxie <moxie@3kgcat.fi> | 2026-03-15 14:17:01 +0200 |
| commit | 37cd862b5e0fbd7ae4d421e0cad8e198d5653381 (patch) | |
| tree | 4de54b38472e2dff034e422cc29fc6e4ad2fc810 /lua/muwiki/links.lua | |
| parent | 97cbb42f24ef8836c2d7738e60d67515384c3f7c (diff) | |
feat: add text_extensions config
Diffstat (limited to 'lua/muwiki/links.lua')
| -rw-r--r-- | lua/muwiki/links.lua | 31 |
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 = {} |
