11local callout = require (' render-markdown.callout' )
2+ local custom_checkbox = require (' render-markdown.custom_checkbox' )
23local icons = require (' render-markdown.icons' )
34local list = require (' render-markdown.list' )
45local logger = require (' render-markdown.logger' )
56local state = require (' render-markdown.state' )
7+ local str = require (' render-markdown.str' )
68local ts = require (' render-markdown.ts' )
79local util = require (' render-markdown.util' )
810
@@ -39,7 +41,7 @@ M.render_node = function(namespace, buf, capture, node)
3941 local background = list .clamp_last (highlights .heading .backgrounds , level )
4042 local foreground = list .clamp_last (highlights .heading .foregrounds , level )
4143
42- local heading_text = { string.rep ( ' ' , padding ) .. heading , { foreground , background } }
44+ local heading_text = { str . pad ( heading , padding ), { foreground , background } }
4345 vim .api .nvim_buf_set_extmark (buf , namespace , start_row , 0 , {
4446 end_row = end_row + 1 ,
4547 end_col = 0 ,
@@ -71,7 +73,7 @@ M.render_node = function(namespace, buf, capture, node)
7173 return
7274 end
7375 -- Requires inline extmarks
74- if vim . fn . has ( ' nvim-0.10 ' ) == 0 then
76+ if not util . has_10 then
7577 return
7678 end
7779
@@ -86,7 +88,7 @@ M.render_node = function(namespace, buf, capture, node)
8688 virt_text_pos = ' inline' ,
8789 })
8890 elseif capture == ' list_marker' then
89- if ts . sibling ( node , { ' task_list_marker_unchecked ' , ' task_list_marker_checked ' }) ~= nil then
91+ if M . sibling_checkbox ( buf , node ) then
9092 -- Hide the list marker for checkboxes rather than replacing with a bullet point
9193 vim .api .nvim_buf_set_extmark (buf , namespace , start_row , start_col , {
9294 end_row = end_row ,
@@ -101,7 +103,7 @@ M.render_node = function(namespace, buf, capture, node)
101103 local level = ts .level_in_section (node , ' list' )
102104 local bullet = list .cycle (state .config .bullets , level )
103105
104- local list_marker_text = { string.rep ( ' ' , leading_spaces or 0 ) .. bullet , highlights .bullet }
106+ local list_marker_text = { str . pad ( bullet , leading_spaces ) , highlights .bullet }
105107 vim .api .nvim_buf_set_extmark (buf , namespace , start_row , start_col , {
106108 end_row = end_row ,
107109 end_col = end_col ,
@@ -118,8 +120,7 @@ M.render_node = function(namespace, buf, capture, node)
118120 local highlight = highlights .quote
119121 local quote = ts .parent_in_section (node , ' block_quote' )
120122 if quote ~= nil then
121- local quote_value = vim .treesitter .get_node_text (quote , buf )
122- local key = callout .get_key_contains (quote_value )
123+ local key = callout .get_key_contains (vim .treesitter .get_node_text (quote , buf ))
123124 if key ~= nil then
124125 highlight = highlights .callout [key ]
125126 end
@@ -139,17 +140,14 @@ M.render_node = function(namespace, buf, capture, node)
139140 checkbox = state .config .checkbox .checked
140141 highlight = highlights .checkbox .checked
141142 end
142- local padding = vim .fn .strdisplaywidth (value ) - vim .fn .strdisplaywidth (checkbox )
143143
144- if padding >= 0 then
145- local checkbox_text = { string.rep (' ' , padding ) .. checkbox , highlight }
146- vim .api .nvim_buf_set_extmark (buf , namespace , start_row , start_col , {
147- end_row = end_row ,
148- end_col = end_col ,
149- virt_text = { checkbox_text },
150- virt_text_pos = ' overlay' ,
151- })
152- end
144+ local checkbox_text = { str .pad_to (value , checkbox ), highlight }
145+ vim .api .nvim_buf_set_extmark (buf , namespace , start_row , start_col , {
146+ end_row = end_row ,
147+ end_col = end_col ,
148+ virt_text = { checkbox_text },
149+ virt_text_pos = ' overlay' ,
150+ })
153151 elseif capture == ' table' then
154152 if state .config .table_style ~= ' full' then
155153 return
@@ -251,4 +249,21 @@ M.render_node = function(namespace, buf, capture, node)
251249 end
252250end
253251
252+ --- @param buf integer
253+ --- @param node TSNode
254+ --- @return boolean
255+ M .sibling_checkbox = function (buf , node )
256+ if ts .sibling (node , { ' task_list_marker_unchecked' , ' task_list_marker_checked' }) ~= nil then
257+ return true
258+ end
259+ local paragraph = ts .sibling (node , { ' paragraph' })
260+ if paragraph == nil then
261+ return false
262+ end
263+ if custom_checkbox .get_starts (vim .treesitter .get_node_text (paragraph , buf )) ~= nil then
264+ return true
265+ end
266+ return false
267+ end
268+
254269return M
0 commit comments