|
95 | 95 |
|
96 | 96 | M.namespace = vim.api.nvim_create_namespace('render-markdown.nvim')
|
97 | 97 |
|
| 98 | +M.clear = function() |
| 99 | + -- Remove existing highlights / virtual text |
| 100 | + vim.api.nvim_buf_clear_namespace(0, M.namespace, 0, -1) |
| 101 | +end |
| 102 | + |
98 | 103 | M.refresh = function()
|
99 | 104 | if not vim.tbl_contains(state.config.file_types, vim.bo.filetype) then
|
100 | 105 | return
|
101 | 106 | end
|
102 |
| - |
103 |
| - -- Remove existing highlights / virtual text |
104 |
| - vim.api.nvim_buf_clear_namespace(0, M.namespace, 0, -1) |
105 |
| - |
| 107 | + -- Needs to happen after file_type check and before mode check |
| 108 | + M.clear() |
106 | 109 | if not vim.tbl_contains(state.config.render_modes, vim.fn.mode()) then
|
107 | 110 | return
|
108 | 111 | end
|
@@ -139,7 +142,11 @@ M.refresh = function()
|
139 | 142 | hl_eol = true,
|
140 | 143 | })
|
141 | 144 | elseif capture == 'item' then
|
142 |
| - local virt_text = { state.config.bullet, highlights.bullet } |
| 145 | + -- List items from tree-sitter should have leading spaces removed, however there are known |
| 146 | + -- edge cases in the parser: https://github.com/tree-sitter-grammars/tree-sitter-markdown/issues/127 |
| 147 | + -- As a result we handle leading spaces here, can remove if this gets fixed upstream |
| 148 | + local _, leading_spaces = value:find('^%s*') |
| 149 | + local virt_text = { string.rep(' ', leading_spaces or 0) .. state.config.bullet, highlights.bullet } |
143 | 150 | vim.api.nvim_buf_set_extmark(0, M.namespace, start_row, start_col, {
|
144 | 151 | end_row = end_row,
|
145 | 152 | end_col = end_col,
|
|
0 commit comments