MeanderingProgrammer / render-markdown.nvim

Plugin to improve viewing Markdown files in Neovim
MIT License
1.34k stars 32 forks source link

bug: highlighting with breakindent #149

Closed will-lynas closed 2 days ago

will-lynas commented 1 week ago

Neovim version (nvim -v)

0.10.0

Operating system

macOS

Terminal emulator / GUI

kitty

Describe the bug

Highlighting is broken with breakindent set.

image
fn main() {
    let complex_data = vec![
        Some(vec![
            (
                "outer",
                vec![
                    ("inner", vec![1, 2, 3]),
                    ("nested", vec![Some(4), None, Some(5)]),
                ],
            ),
            ("another", vec![("deep", vec![vec![6, 7], vec![8, 9, 10]])]),
        ]),
        None,
        Some(vec![("last", vec![("final", vec![11, 12, 13, 14])])]),
    ];

    process_data(complex_data);
}

fn process_data(data: Vec<Option<Vec<(&str, Vec<(&str, Vec<i32>)>)>>>) {
    for item in data.iter().flatten() {
        for (outer_key, outer_value) in item {
            println!("Outer key: {}", outer_key);
            for (inner_key, inner_value) in outer_value {
                println!(" Inner key: {}", inner_key);
                println!(" Values: {:?}", inner_value);
            }
        }
    }
}

Expected behavior

Every line should have the code block background highlight

Healthcheck output


render-markdown.nvim [version] ~
- OK plugin 6.3.2
- 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
- OK latex: parser installed

render-markdown.nvim [executables] ~
- WARNING latex2text: not installed
  - ADVICE:
    - Disable LaTeX support to avoid this warning by setting { latex = { enabled = false } }

render-markdown.nvim [conflicts] ~
- OK headlines: not installed
- WARNING obsidian: installed
  - ADVICE:
    - Ensure UI is disabled by setting ui = { enable = false } in obsidian.nvim config
    - Acknowledge conflicts to avoid this warning by setting { acknowledge_conflicts = true }

Plugin configuration

return {
    "MeanderingProgrammer/render-markdown.nvim",
    ft = { "markdown", "Avante" },
    opts = {
        file_types = { "markdown", "Avante" },
        heading = {
            enabled = false,
        },
        code = {
            sign = false,
            style = "normal",
            border = "thick",
        },
        bullet = {
            right_pad = 1,
        },
        link = {
            image = "",
            email = "",
            hyperlink = "",
        },
        pipe_table = {
            style = "normal",
        },
    },
}

Plugin error log

N/A

Confirmations

Additional information

Original issue: https://github.com/yetone/avante.nvim/issues/464

MeanderingProgrammer commented 1 week ago

Hmm, I'm not really sure what there is to do here.

The background highlight is created with the following:

vim.api.nvim_buf_set_extmark(buf, namespace, row, col, {
    end_row = row + 1,
    hl_group = 'RenderMarkdownCode',
    hl_eol = true,
})

Setting virt_text_repeat_linebreak does not have any impact since we're not adding any virtual text. The highlight does get wrapped, just not in the breakindent area.

Ideally some extmark options like hl_group would be extended through the breakindent area but that would need to be added to neovim and I'm not sure how feasible that would be.

MeanderingProgrammer commented 1 week ago

Added a comment to the issue in avante.nvim for setting breakindent via win_options.

MeanderingProgrammer commented 1 week ago

There are a few workarounds for this all of which involve disabling breakindent in some way:

  1. Create ftplugin/<filetype>.vim, disable breakindent or set showbreak=NONE
  2. Create a FileType autocommand, set above options in callback
  3. Use win_options for this plugin to disable breakindent: win_options = { breakindent = { default = true, rendered = false } }
MeanderingProgrammer commented 1 week ago

Have opened a feature request in neovim to see if this behavior can be supported on their side or if there's something I can do here: https://github.com/neovim/neovim/issues/30255

will-lynas commented 1 week ago

That's awesome, thank you

MeanderingProgrammer commented 2 days ago

Since the solution here will require an update to Neovim I'm going to resolve this issue. Will track through the issue in core.