From 7fb3ab37725941a0c0801fdd76661f627881b40b Mon Sep 17 00:00:00 2001 From: Jason Paris Date: Tue, 18 Nov 2025 13:29:53 -0500 Subject: [PATCH] fix: support YAML list format for frontmatter tags The tag search parser previously only supported bracket format tags: [tag1, tag2] but failed to parse the standard YAML list format with tags on separate lines (tags:\n - tag1). This caused "No tags found in frontmatter" errors for notes using list format. Updated parser to handle both formats: - Bracket format: tags: [tag1, tag2, tag3] - YAML list format: tags:\n - tag1\n - tag2 Parser now enters list mode when tags: line is not in bracket format and processes subsequent lines starting with - until hitting a non-list item or end of frontmatter section. --- lua/markdown-notes/notes.lua | 39 +++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/lua/markdown-notes/notes.lua b/lua/markdown-notes/notes.lua index 6380ef7..29b5af6 100644 --- a/lua/markdown-notes/notes.lua +++ b/lua/markdown-notes/notes.lua @@ -170,17 +170,36 @@ function M.search_tags() for _, file in ipairs(all_files) do local content = vim.fn.readfile(file) local in_frontmatter = false + local in_tags_list = false - for _, line in ipairs(content) do + for i, line in ipairs(content) do if line == "---" then in_frontmatter = not in_frontmatter - elseif in_frontmatter and line:match("^tags:") then - -- Extract tags from YAML array format: tags: [tag1, tag2, tag3] - local tags_line = line:gsub("^tags:%s*", "") - if tags_line:match("^%[.*%]$") then - -- Remove brackets and split by comma - local tags_content = tags_line:gsub("^%[", ""):gsub("%]$", "") - for tag in tags_content:gmatch("[^,]+") do + in_tags_list = false + elseif in_frontmatter then + if line:match("^tags:") then + -- Extract tags from YAML array format: tags: [tag1, tag2, tag3] + local tags_line = line:gsub("^tags:%s*", "") + if tags_line:match("^%[.*%]$") then + -- Remove brackets and split by comma + local tags_content = tags_line:gsub("^%[", ""):gsub("%]$", "") + for tag in tags_content:gmatch("[^,]+") do + local clean_tag = tag:gsub("%s", ""):gsub('"', ""):gsub("'", "") + if clean_tag ~= "" then + if not tags[clean_tag] then + tags[clean_tag] = {} + end + table.insert(tags[clean_tag], file) + end + end + else + -- YAML list format: tags are on following lines starting with - + in_tags_list = true + end + elseif in_tags_list and line:match("^%s*-%s+") then + -- Extract tag from YAML list item: " - tagname" + local tag = line:match("^%s*-%s+(.+)") + if tag then local clean_tag = tag:gsub("%s", ""):gsub('"', ""):gsub("'", "") if clean_tag ~= "" then if not tags[clean_tag] then @@ -189,8 +208,10 @@ function M.search_tags() table.insert(tags[clean_tag], file) end end + elseif in_tags_list and not line:match("^%s*-%s+") and not line:match("^%s*$") then + -- Hit a non-list-item, non-empty line, stop looking for tags + in_tags_list = false end - break -- Only process first tags line in frontmatter end end end