@@ -37,28 +37,6 @@ 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-
6240--- @param root TSNode
6341M .markdown = function (root )
6442 local highlights = state .config .highlights
@@ -95,10 +73,10 @@ M.markdown = function(root)
9573 -- edge cases in the parser: https://github.com/tree-sitter-grammars/tree-sitter-markdown/issues/127
9674 -- As a result we handle leading spaces here, can remove if this gets fixed upstream
9775 local _ , leading_spaces = value :find (' ^%s*' )
98- -- Get the level of the list_marker by counting the number of parent list nodes
9976 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 }
77+ local bullet = list .cycle (state .config .bullets , level )
78+
79+ local virt_text = { string.rep (' ' , leading_spaces or 0 ) .. bullet , highlights .bullet }
10280 vim .api .nvim_buf_set_extmark (0 , M .namespace , start_row , start_col , {
10381 end_row = end_row ,
10482 end_col = end_col ,
@@ -167,6 +145,28 @@ M.markdown = function(root)
167145 end
168146end
169147
148+ --- Walk through all parent nodes and count the number of nodes with type list
149+ --- to calculate the level of the given node
150+ --- @param node TSNode
151+ --- @return integer
152+ M .calculate_list_level = function (node )
153+ local level = 0
154+ local parent = node :parent ()
155+ while parent ~= nil do
156+ local parent_type = parent :type ()
157+ if vim .tbl_contains ({ ' section' , ' document' }, parent_type ) then
158+ -- when reaching a section or the document we are clearly at the
159+ -- top of the list
160+ break
161+ elseif parent_type == ' list' then
162+ -- found a list increase the level and continue
163+ level = level + 1
164+ end
165+ parent = parent :parent ()
166+ end
167+ return level
168+ end
169+
170170--- @param root TSNode
171171M .markdown_inline = function (root )
172172 local highlights = state .config .highlights
0 commit comments