diff options
| author | moxie <moxie@3kgcat.fi> | 2026-03-14 10:28:08 +0200 |
|---|---|---|
| committer | moxie <moxie@3kgcat.fi> | 2026-03-14 10:29:54 +0200 |
| commit | c8dc1635f8a921269f714117f414bbc7ba24f9fd (patch) | |
| tree | 336a0bb466a5e023c0a0e6472c9876ff7458de68 /lua/muwiki/links/detection.lua | |
| parent | ffc0482ab89924cb35155fa82033e3d0ddc6c93d (diff) | |
refactor: consolidate modules and improve structure
Diffstat (limited to 'lua/muwiki/links/detection.lua')
| -rw-r--r-- | lua/muwiki/links/detection.lua | 58 |
1 files changed, 0 insertions, 58 deletions
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 |
