MeanderingProgrammer / render-markdown.nvim

Plugin to improve viewing Markdown files in Neovim
MIT License
1.72k stars 38 forks source link

bug: Wrong symbol being rendered for custom checkbox #162

Closed Lau-San closed 1 month ago

Lau-San commented 1 month ago

Neovim version (nvim -v)

0.10.1

Operating system

Linux

Terminal emulator / GUI

Kitty

Describe the bug

In the config, I setup checkbox config like this:

checkbox = {
    unchecked = { icon = ' ' },
    checked = { icon = ' ' },
    custom = {
        incomplete = { raw = '[/]', rendered = ' ', highlight = 'DiagnosticWarn' },
         cancelled = { raw = '[-]', rendered = ' ', highlight = 'DiagnosticUnnecessary' },
         migrated = { raw = '[>]', rendered = ' ', highlight = 'DiagnosticInfo' },
         pinned = { raw = '[*]', rendered = ' ', highlight = 'DiagnosticHint' },
    }
}

image

I've been using the plugin without issues and almos all of these checkboxes work as expected, except cancelled:

- [ ] Test task
- [x] Test task
- [>] Test task
- [*] Test task
- [-] Test task

image

As you can see, all tasks are rendered with the icons I specified, except the last one.

Expected behavior

The last task should've rendered like this (I pasted the icon directly from the config to demonstrate):

image

Healthcheck output

==============================================================================
render-markdown: require("render-markdown.health").check()

render-markdown.nvim [version] ~
- OK plugin 6.3.6
- OK neovim >= 0.10

render-markdown.nvim [configuration] ~
- OK valid

render-markdown.nvim [nvim-treesitter] ~
- OK installed
- OK markdown: parser installed
- OK markdown: highlight enabled
- OK markdown_inline: parser installed
- OK markdown_inline: highlight enabled

render-markdown.nvim [executables] ~
- OK none to check

render-markdown.nvim [conflicts] ~
- OK headlines: not installed
- OK obsidian: installed but should not conflict

Plugin configuration

local markdown = {
    'MeanderingProgrammer/markdown.nvim',
    opts = {
        latex = { enabled = false },
        win_options = {
            conceallevel = { rendered = 2 }
        },
        heading = {
            position = 'overlay',
            icons = { '󰎤 ', '󰎧 ', '󰎪 ', '󰎭 ', '󰎱 ', '󰎳 ' },
            width = 'full',
            left_pad = 1,
            right_pad = 2,
            -- min_width = 80,
            border = false,
            backgrounds = {
                'RenderMarkdownH2BG',
                'RenderMarkdownH2BG',
                'RenderMarkdownH2BG',
                'RenderMarkdownH2BG',
                'RenderMarkdownH2BG',
                'RenderMarkdownH2BG'
            }
        },
        code = {
            -- position = 'right'
            width = 'block',
            min_width = 80,
            left_pad = 2
        },
        bullet = {
            right_pad = 2
        },
        checkbox = {
            unchecked = { icon = ' ' },
            checked = { icon = ' ' },
            custom = {
                incomplete = { raw = '[/]', rendered = ' ', highlight = 'DiagnosticWarn' },
                cancelled = { raw = '[-]', rendered = ' ', highlight = 'DiagnosticUnnecessary' },
                migrated = { raw = '[>]', rendered = ' ', highlight = 'DiagnosticInfo' },
                pinned = { raw = '[*]', rendered = ' ', highlight = 'DiagnosticHint' },
            }
        },
        callout = {
            note = { raw = '[!NOTE]', rendered = '󰋽 Note', highlight = 'RenderMarkdownInfo' },
            tip = { raw = '[!TIP]', rendered = '󰌶 Tip', highlight = 'RenderMarkdownSuccess' },
            important = { raw = '[!IMPORTANT]', rendered = '󰅾 Important', highlight = 'RenderMarkdownHint' },
            warning = { raw = '[!WARNING]', rendered = '󰀪 Warning', highlight = 'RenderMarkdownError' },
            attention = { raw = '[!ATTENTION]', rendered = '󰀪 Attention', highlight = 'RenderMarkdownWarn' },
            caution = { raw = '[!CAUTION]', rendered = '󰳦 Caution', highlight = 'RenderMarkdownError' },
            abstract = { raw = '[!ABSTRACT]', rendered = '󰨸 Abstract', highlight = 'RenderMarkdownInfo' },
            todo = { raw = '[!TODO]', rendered = '󰗡 Todo', highlight = 'RenderMarkdownInfo' },
            success = { raw = '[!SUCCESS]', rendered = '󰄬 Success', highlight = 'RenderMarkdownSuccess' },
            question = { raw = '[!QUESTION]', rendered = '󰘥 Question', highlight = 'RenderMarkdownWarn' },
            failure = { raw = '[!FAILURE]', rendered = '󰅖 Failure', highlight = 'RenderMarkdownError' },
            danger = { raw = '[!DANGER]', rendered = '󱐌 Danger', highlight = 'RenderMarkdownError' },
            bug = { raw = '[!BUG]', rendered = '󰨰 Bug', highlight = 'RenderMarkdownError' },
            example = { raw = '[!EXAMPLE]', rendered = '󰉹 Example', highlight = 'RenderMarkdownHint' },
            quote = { raw = '[!QUOTE]', rendered = '󱆨 Quote', highlight = 'RenderMarkdownQuote' },
        }
    }
}

Plugin error log

N/A

Confirmations

Additional information

I thought it was a problem with my Kitty fonts config, but I checked and all codepoints are configured based on the official Nerd Fonts wiki and I have the last version. In any case, the icon clearly works as I pasted it in the config myself, it only shows a different icon when rendering the tasks in markdown.

I also have obsidian.nvim plugin, but I disabled it's markdown rendering features so it doesn't conflict. I don't even have custom checkboxes configured there and as you can see, all other custom checkboxes from the render-markdown config work fine.

Lau-San commented 1 month ago

Update: it seems the problem only happens when trying to configure [-]. I changed it to [c] and now it works, but does that mean that [-] is not configurable?

Weirly enough, when configuring [-] it seemed to work SOMETIMES. Like I would open nvim and then a markdown file, and it would look fine, but after closing neovim and opening it again, then opening the same file, suddenly the icon looks wrong again. It just wasn't consistent, and more often than not, it would have the wrong icon. Surely that's not supposed to happen?

MeanderingProgrammer commented 1 month ago

Due to the default value of checkboxes: https://github.com/MeanderingProgrammer/render-markdown.nvim?tab=readme-ov-file#checkboxes

custom = {
    todo = { raw = '[-]', rendered = '󰥔 ', highlight = 'RenderMarkdownTodo' },
}

Since the [-] symbol is used twice, the one that gets selected will be random since iterating through a table does not guarantee order.

Any of these solutions will work: