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 | |
| parent | 97cbb42f24ef8836c2d7738e60d67515384c3f7c (diff) | |
feat: add text_extensions config
| -rw-r--r-- | lua/muwiki/config.lua | 1 | ||||
| -rw-r--r-- | lua/muwiki/links.lua | 31 |
2 files changed, 14 insertions, 18 deletions
diff --git a/lua/muwiki/config.lua b/lua/muwiki/config.lua index 9d668b9..a2121b1 100644 --- a/lua/muwiki/config.lua +++ b/lua/muwiki/config.lua @@ -3,6 +3,7 @@ local M = {} M.options = { dirs = nil, index_file = 'index.md', + text_extensions = { 'txt', 'py', 'rb', 'js', 'ts', 'lua', 'sh', 'bash', 'zsh', 'vim', 'json', 'yaml', 'yml', 'toml', 'xml', 'html', 'css' }, } function M.setup(opts) 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 = {} |
