From 6aa7b83257c8b0b06f261d413c922514adeed3b8 Mon Sep 17 00:00:00 2001 From: Jason Paris Date: Sat, 19 Jul 2025 16:55:23 -0400 Subject: [PATCH] fix: normalize link paths to be relative to vault root Link insertion now strips leading './' from file paths to ensure all generated links are consistently relative to the vault root directory, regardless of the current file's location. Fixes #25 --- lua/markdown-notes/links.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/markdown-notes/links.lua b/lua/markdown-notes/links.lua index 64fbb78..2b61f5d 100644 --- a/lua/markdown-notes/links.lua +++ b/lua/markdown-notes/links.lua @@ -4,8 +4,10 @@ local M = {} -- Helper function to insert a link at cursor position local function insert_link_at_cursor(file_path) + -- Normalize path by removing leading ./ if present + local normalized_path = file_path:gsub("^%./", "") -- Remove .md extension but keep the full path - local link_path = file_path:gsub("%.md$", "") + local link_path = normalized_path:gsub("%.md$", "") local link = "[[" .. link_path .. "]]" -- Insert link at cursor