From c8dc1635f8a921269f714117f414bbc7ba24f9fd Mon Sep 17 00:00:00 2001 From: moxie Date: Sat, 14 Mar 2026 10:28:08 +0200 Subject: refactor: consolidate modules and improve structure --- lua/muwiki/links/detection.lua | 58 ------------------------------------------ 1 file changed, 58 deletions(-) delete mode 100644 lua/muwiki/links/detection.lua (limited to 'lua/muwiki/links/detection.lua') diff --git a/lua/muwiki/links/detection.lua b/lua/muwiki/links/detection.lua deleted file mode 100644 index 7b1f317..0000000 --- a/lua/muwiki/links/detection.lua +++ /dev/null @@ -1,58 +0,0 @@ -local M = {} - -local function get_link_type(target) - if target:match('^https?://') then - return 'web' - end - if target:match('^file://') then - return 'file' - end - return 'wiki' -end - -function M.get_link() - local cursor = vim.api.nvim_win_get_cursor(0) - - local ok, node = pcall(vim.treesitter.get_node, { - bufnr = 0, - pos = { cursor[1] - 1, cursor[2] }, - lang = 'markdown', - ignore_injections = false, - }) - - if not ok or not node then - return nil - end - - local link_node = node ---@type TSNode|nil - while link_node and link_node:type() ~= 'inline_link' do - link_node = link_node:parent() - end - - if not link_node then - return nil - end - - local text_node, dest_node - for child in link_node:iter_children() do - local t = child:type() - if t == 'link_text' then - text_node = child - elseif t == 'link_destination' then - dest_node = child - end - end - - if not text_node or not dest_node then - return nil - end - - local destination = vim.treesitter.get_node_text(dest_node, 0) - return { - text = vim.treesitter.get_node_text(text_node, 0), - target = destination, - type = get_link_type(destination), - } -end - -return M -- cgit v1.2.3