From 5f3273c0734104846da590ce9678be54c4da3585 Mon Sep 17 00:00:00 2001 From: Masahiro Kasashima Date: Fri, 19 May 2023 22:15:56 +0900 Subject: [PATCH 1/2] Support markdown multi line header notation --- lua/symbols-outline/markdown.lua | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lua/symbols-outline/markdown.lua b/lua/symbols-outline/markdown.lua index e035a55..c2b77d9 100644 --- a/lua/symbols-outline/markdown.lua +++ b/lua/symbols-outline/markdown.lua @@ -16,10 +16,24 @@ function M.handle_markdown() is_inside_code_block = not is_inside_code_block end - header, title = string.match(value, '^(#+)%s+(.*)$') - if header and not is_inside_code_block then - depth = #header + 1 + local next_value = lines[line+1] + local is_emtpy_line = #value:gsub("^%s*(.-)%s*$", "%1") == 0 + local header, title = string.match(value, '^(#+)%s+(.*)$') + if not header and next_value and not is_emtpy_line then + if string.match(next_value, '^===+%s*$') then + header = '#' + title = value + elseif string.match(next_value, '^---+%s*$') then + header = '##' + title = value + end + end + + if header and not is_inside_code_block then + local depth = #header + 1 + + local parent for i = depth - 1, 1, -1 do if level_symbols[i] ~= nil then parent = level_symbols[i].children @@ -36,7 +50,7 @@ function M.handle_markdown() end max_level = depth - entry = { + local entry = { kind = 13, name = title, selectionRange = { From 33f1cf14b1a70d83f55f7cdbac633a07e70539d5 Mon Sep 17 00:00:00 2001 From: Masahiro Kasashima Date: Fri, 19 May 2023 22:27:19 +0900 Subject: [PATCH 2/2] Allow any number of =s and -s --- lua/symbols-outline/markdown.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/symbols-outline/markdown.lua b/lua/symbols-outline/markdown.lua index c2b77d9..8503d30 100644 --- a/lua/symbols-outline/markdown.lua +++ b/lua/symbols-outline/markdown.lua @@ -21,10 +21,10 @@ function M.handle_markdown() local header, title = string.match(value, '^(#+)%s+(.*)$') if not header and next_value and not is_emtpy_line then - if string.match(next_value, '^===+%s*$') then + if string.match(next_value, '^=+%s*$') then header = '#' title = value - elseif string.match(next_value, '^---+%s*$') then + elseif string.match(next_value, '^-+%s*$') then header = '##' title = value end