From 37cd862b5e0fbd7ae4d421e0cad8e198d5653381 Mon Sep 17 00:00:00 2001 From: moxie Date: Sun, 15 Mar 2026 14:17:01 +0200 Subject: feat: add text_extensions config --- lua/muwiki/links.lua | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'lua/muwiki/links.lua') 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 = {} -- cgit v1.2.3