MeanderingProgrammer / markdown.nvim

Plugin to improve viewing Markdown files in Neovim
MIT License
503 stars 20 forks source link

fix: stop rendering bullet points for task lists #22

Closed dvnatanael closed 2 months ago

dvnatanael commented 2 months ago

Fixes #18

MeanderingProgrammer commented 2 months ago

Hi there,

I appreciate the attempt, and I do believe this accomplishes the goal.

Ultimately the query and the logic was getting a little too confusing. Having the query filter out the bullet point then going to the previous node to get the total number of spaces and applying this inlined concealed text was just a little hard to track for me. This is definitely just a preference on my part.

I merged a fix for this here: https://github.com/MeanderingProgrammer/markdown.nvim/commit/e38795f3641ffb5702bf289f76df8a81f6163d32

dvnatanael commented 2 months ago

No problem, and thank you for the fix. I have taken a look at the fix and it does indeed look much simpler to follow.

In my fix, I was trying to collapse the task list marker (e.g. - [ ]) into the replacement text. I didn't realize that you preferred to avoid the text jumping behavior 😅.

MeanderingProgrammer commented 2 months ago

Yeah, I had originally written it with the jumping behavior like so:

if M.is_sibling_checkbox(node) then
    -- Hide the list marker for checkboxes rather than replacing with a bullet point
    vim.api.nvim_buf_set_extmark(0, namespace, start_row, start_col, {
        end_row = end_row,
        end_col = end_col,
        conceal = '',
    })
else
    -- List markers from tree-sitter should have leading spaces removed, however there are known
    -- edge cases in the parser: https://github.com/tree-sitter-grammars/tree-sitter-markdown/issues/127
    -- As a result we handle leading spaces here, can remove if this gets fixed upstream
    local _, leading_spaces = value:find('^%s*')
    local level = M.calculate_list_level(node)
    local bullet = list.cycle(state.config.bullets, level)

    local virt_text = { string.rep(' ', leading_spaces or 0) .. bullet, highlights.bullet }
    vim.api.nvim_buf_set_extmark(0, namespace, start_row, start_col, {
        end_row = end_row,
        end_col = end_col,
        virt_text = { virt_text },
        virt_text_pos = 'overlay',
    })
end

But found it strange if you enter the line that a dash (or other marker) would popup and went with just making the dash "invisible".