@@ -37,6 +37,28 @@ M.refresh = function()
3737 end )
3838end
3939
40+ --- Walk through all parent nodes and count the number of nodes with type list
41+ --- to calculate the level of the given node
42+ --- @param node TSNode
43+ --- @return integer
44+ M .calculate_list_level = function (node )
45+ local candidate = node :parent ()
46+ local level = 0
47+ while candidate ~= nil do
48+ local candidate_type = candidate :type ()
49+ if candidate_type == " section" or candidate_type == " document" then
50+ -- when reaching a section or the document we are clearly at the
51+ -- top of the list
52+ break
53+ elseif candidate_type == " list" then
54+ -- found a list increase the level and continue
55+ level = level + 1
56+ end
57+ candidate = candidate :parent ()
58+ end
59+ return level
60+ end
61+
4062--- @param root TSNode
4163M .markdown = function (root )
4264 local highlights = state .config .highlights
@@ -73,7 +95,10 @@ M.markdown = function(root)
7395 -- edge cases in the parser: https://github.com/tree-sitter-grammars/tree-sitter-markdown/issues/127
7496 -- As a result we handle leading spaces here, can remove if this gets fixed upstream
7597 local _ , leading_spaces = value :find (' ^%s*' )
76- local virt_text = { string.rep (' ' , leading_spaces or 0 ) .. state .config .bullet , highlights .bullet }
98+ -- Get the level of the list_marker by counting the number of parent list nodes
99+ local level = M .calculate_list_level (node )
100+ local bullet_marker = list .cycle (state .config .bullets , level )
101+ local virt_text = { string.rep (' ' , leading_spaces or 0 ) .. bullet_marker , highlights .bullet }
77102 vim .api .nvim_buf_set_extmark (0 , M .namespace , start_row , start_col , {
78103 end_row = end_row ,
79104 end_col = end_col ,
0 commit comments