@@ -37,28 +37,6 @@ M.refresh = function()
37
37
end )
38
38
end
39
39
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
-
62
40
--- @param root TSNode
63
41
M .markdown = function (root )
64
42
local highlights = state .config .highlights
@@ -95,10 +73,10 @@ M.markdown = function(root)
95
73
-- edge cases in the parser: https://github.com/tree-sitter-grammars/tree-sitter-markdown/issues/127
96
74
-- As a result we handle leading spaces here, can remove if this gets fixed upstream
97
75
local _ , leading_spaces = value :find (' ^%s*' )
98
- -- Get the level of the list_marker by counting the number of parent list nodes
99
76
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 }
102
80
vim .api .nvim_buf_set_extmark (0 , M .namespace , start_row , start_col , {
103
81
end_row = end_row ,
104
82
end_col = end_col ,
@@ -167,6 +145,28 @@ M.markdown = function(root)
167
145
end
168
146
end
169
147
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
+
170
170
--- @param root TSNode
171
171
M .markdown_inline = function (root )
172
172
local highlights = state .config .highlights
0 commit comments