@@ -3,6 +3,8 @@ local List = require('render-markdown.lib.list')
3
3
local Str = require (' render-markdown.lib.str' )
4
4
5
5
--- @class render.md.data.ListMarker
6
+ --- @field marker render.md.Node
7
+ --- @field ordered boolean
6
8
--- @field spaces integer
7
9
--- @field checkbox ? render.md.CustomCheckbox
8
10
@@ -16,55 +18,63 @@ Render.__index = Render
16
18
function Render :setup ()
17
19
self .bullet = self .config .bullet
18
20
21
+ local marker = self .node :child_at (0 )
22
+ if marker == nil then
23
+ return false
24
+ end
25
+
19
26
self .data = {
27
+ marker = marker ,
28
+ ordered = vim .tbl_contains ({ ' list_marker_dot' , ' list_marker_parenthesis' }, marker .type ),
20
29
-- List markers from tree-sitter should have leading spaces removed, however there are edge
21
30
-- cases in the parser: https://github.com/tree-sitter-grammars/tree-sitter-markdown/issues/127
22
31
-- As a result we account for leading spaces here, can remove if this gets fixed upstream
23
- spaces = Str .spaces (' start' , self . node .text ),
32
+ spaces = Str .spaces (' start' , marker .text ),
24
33
checkbox = self .context :get_checkbox (self .node ),
25
34
}
26
35
27
36
return true
28
37
end
29
38
30
39
function Render :render ()
31
- if self :sibling_checkbox () then
40
+ if self :has_checkbox () then
32
41
-- Hide the list marker for checkboxes rather than replacing with a bullet point
33
42
self :hide_marker ()
34
43
self :highlight_scope ()
35
44
else
36
45
if not self .bullet .enabled then
37
46
return
38
47
end
39
- local level , root_list = self .node :level_in_section (' list' )
48
+ local level , root = self .node :level_in_section (' list' )
40
49
self :icon (level )
41
- self :padding (root_list )
50
+ self :padding (root )
42
51
end
43
52
end
44
53
45
54
--- @private
46
55
--- @return boolean
47
- function Render :sibling_checkbox ()
56
+ function Render :has_checkbox ()
48
57
if not self .config .checkbox .enabled then
49
58
return false
50
59
end
51
60
if self .data .checkbox ~= nil then
52
61
return true
53
62
end
54
- if self .node :sibling (' task_list_marker_unchecked' ) ~= nil then
63
+ if self .data . marker :sibling (' task_list_marker_unchecked' ) ~= nil then
55
64
return true
56
65
end
57
- if self .node :sibling (' task_list_marker_checked' ) ~= nil then
66
+ if self .data . marker :sibling (' task_list_marker_checked' ) ~= nil then
58
67
return true
59
68
end
60
69
return false
61
70
end
62
71
63
72
--- @private
64
73
function Render :hide_marker ()
65
- self .marks :add (' check_icon' , self .node .start_row , self .node .start_col + self .data .spaces , {
66
- end_row = self .node .end_row ,
67
- end_col = self .node .end_col ,
74
+ local node = self .data .marker
75
+ self .marks :add (' check_icon' , node .start_row , node .start_col + self .data .spaces , {
76
+ end_row = node .end_row ,
77
+ end_col = node .end_col ,
68
78
conceal = ' ' ,
69
79
})
70
80
end
@@ -74,54 +84,48 @@ function Render:highlight_scope()
74
84
if self .data .checkbox == nil then
75
85
return
76
86
end
77
- self :checkbox_scope (self .data .checkbox .scope_highlight )
87
+ self :checkbox_scope (self .node : child ( ' paragraph ' ), self . data .checkbox .scope_highlight )
78
88
end
79
89
80
90
--- @private
81
91
--- @param level integer
82
92
function Render :icon (level )
83
- local icon = List .cycle (self .bullet .icons , level )
93
+ local icons = self .data .ordered and self .bullet .ordered_icons or self .bullet .icons
94
+ local icon = List .cycle (icons , level )
84
95
if type (icon ) == ' table' then
85
- local item = self .node :parent (' list_item' )
86
- if item == nil then
87
- return
88
- end
89
- icon = List .clamp (icon , item :sibling_count (' list_item' ))
96
+ icon = List .clamp (icon , self .node :sibling_count (' list_item' ))
90
97
end
91
98
if icon == nil then
92
99
return
93
100
end
101
+ local node = self .data .marker
94
102
local text = Str .pad (self .data .spaces ) .. icon
95
103
local position , conceal = ' overlay' , nil
96
- if Str .width (text ) > Str .width (self . node .text ) then
104
+ if Str .width (text ) > Str .width (node .text ) then
97
105
position , conceal = ' inline' , ' '
98
106
end
99
- self .marks :add (' bullet' , self . node .start_row , self . node .start_col , {
100
- end_row = self . node .end_row ,
101
- end_col = self . node .end_col ,
107
+ self .marks :add (' bullet' , node .start_row , node .start_col , {
108
+ end_row = node .end_row ,
109
+ end_col = node .end_col ,
102
110
virt_text = { { text , self .bullet .highlight } },
103
111
virt_text_pos = position ,
104
112
conceal = conceal ,
105
113
})
106
114
end
107
115
108
116
--- @private
109
- --- @param root_list ? render.md.Node
110
- function Render :padding (root_list )
117
+ --- @param root ? render.md.Node
118
+ function Render :padding (root )
111
119
if self .bullet .left_pad <= 0 and self .bullet .right_pad <= 0 then
112
120
return
113
121
end
114
- local list_item = self .node :parent (' list_item' )
115
- if list_item == nil then
116
- return
117
- end
118
- local left_col = root_list ~= nil and root_list .start_col or list_item .start_col
122
+ local left_col = root ~= nil and root .start_col or self .node .start_col
119
123
120
- local next_list = list_item :child (' list' )
121
- local end_row = next_list ~= nil and next_list .start_row or list_item .end_row
124
+ local next_list = self . node :child (' list' )
125
+ local end_row = next_list ~= nil and next_list .start_row or self . node .end_row
122
126
123
- for row = list_item .start_row , end_row - 1 do
124
- local right_col = row == list_item . start_row and self .node .end_col - 1 or left_col
127
+ for row = self . node .start_row , end_row - 1 do
128
+ local right_col = row == self . node . start_row and self .data . marker .end_col - 1 or left_col
125
129
self :padding_mark (row , left_col , self .bullet .left_pad )
126
130
self :padding_mark (row , right_col , self .bullet .right_pad )
127
131
end
0 commit comments