Skip to content

bug: Incorrct padding on first non-toplevel bullet when right_pad != 0 #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
heddxh opened this issue Oct 6, 2024 · 11 comments
Closed
2 tasks done
Labels
not a bug Not a bug in this plugin

Comments

@heddxh
Copy link

heddxh commented Oct 6, 2024

Neovim version (nvim -v)

0.10.1

Neovim distribution

N/A

Operating system

Arch Linux

Terminal emulator / GUI

konsole, kitty

Describe the bug

bullet

As the screenshot, top-level bullet look good. But at level-2 or smaller, the first bullet have no padding on the right though I set right_pad = 1.

Expected behavior

Aligned all sub bullet with same right padding.

Healthcheck output

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

render-markdown.nvim [version] ~
- OK plugin 7.3.0
- 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
- WARNING latex: parser not installed
  - ADVICE:
    - Disable LaTeX support to avoid this warning by setting { latex = { enabled = false } }

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
- OK obsidian: not installed

Plugin configuration

{
    'MeanderingProgrammer/render-markdown.nvim',
    ft = support_ft,
    opts = {
      bullet = {
        enabled = true,
        icons = { '', '', '', '' },
        left_pad = 0,
        right_pad = 1,
        highlight = 'RenderMarkdownBullet',
      },
      code = {
        sign = false,
        width = 'block',
        right_pad = 1,
      },
      heading = {
        enabled = false,
        sign = false,
        icons = {},
        border_virtual = true,
        backgrounds = { '' },
      },
    },
    dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-tree/nvim-web-devicons' },
}

Plugin error log

N/A

Confirmations

  • I have updated this plugin to the latest version using my plugin manager
  • I have provided text for all screenshots & understand that my issue will be closed if I have not

Additional information

Additionally, As the wiki said, default setting will also render a space between the bullet sign and the text. But on my machine only if I increase the value of bullet.right_pad then it looks like this demo.

@heddxh heddxh added the bug Something isn't working label Oct 6, 2024
@MeanderingProgrammer
Copy link
Owner

Instructions not followed, I am unable to replicate with this input.

* aaaaa
* bbbbb
    * xxxxx
    * yyyyy
        * qqqqq
        * wwwww
        * eeeee
* ccccc

Give me the text causing the problem.

@heddxh
Copy link
Author

heddxh commented Oct 8, 2024

* aaaaa
* bbbbb
    * xxxxx
    * yyyyy
        * qqqqq
        * wwwww
        * eeeee
* ccccc

Just these lines will make the problem.
By the way, using RenderMarkdown debug on line3:

Decorations on row: 2                                                       
============================================================================          
row: 2                                                                                
column: 2 -> 6                                                                        
hide: true                                                                            
  virt_text: "  ○"::(Bullet)                                                          
  virt_text_pos: overlay                                                              
============================================================================          
row: 2                                                                                
column: 5                                                                             
hide: false                                                                           
  virt_text: " "::(Normal)                                                            
  virt_text_pos: inline      

On line 4(the correct line):

Decorations on row: 3 
============================================================================          
row: 3                                                                                
column: 4 -> 6                                                                        
hide: true                                                                            
  virt_text: "○"::(Bullet)                                                            
  virt_text_pos: overlay                                                              
============================================================================          
row: 3                                                                                
column: 5                                                                             
hide: false                                                                           
  virt_text: " "::(Normal)                                                            
  virt_text_pos: inline  

@MeanderingProgrammer
Copy link
Owner

You may be experiencing the issue outlined here: #93 (comment)

Can you try updating treesitter?

MeanderingProgrammer added a commit that referenced this issue Oct 9, 2024
## Details

Issue: #199

Issue may not be related to this but setting a priority of 0 to right
padding like is done with left padding seems like the correct approach.

Update unit tests to validate priority value as well.
@heddxh
Copy link
Author

heddxh commented Oct 10, 2024

After disable treesitter hignlight using TSBufDisable highlight, it works fine. This is my treesitter config:

{ -- Highlight, edit, and navigate code
    'nvim-treesitter/nvim-treesitter',
    build = ':TSUpdate',
    main = 'nvim-treesitter.configs', -- Sets main module to use for opts
    opts = {
      ensure_installed = {
        'bash',
        'c',
        'diff',
        'html',
        'lua',
        'luadoc',
        'markdown',
        'markdown_inline',
        'query',
        'vim',
        'vimdoc',
        'java',
        'fish',
        'python',
      },
      auto_install = true,
      highlight = {
        enable = true,
        additional_vim_regex_highlighting = { 'ruby' },
      },
      indent = { enable = true, disable = { 'ruby' } },
    },
  }

Is this expected?

@MeanderingProgrammer
Copy link
Owner

No, this is not expected, can you try updating nvim-treesitter using your plugin manager, with that the parsers should also be updated.

If this doesn't fix anything do you know if you have any custom treesitter highlights in your config?

@heddxh
Copy link
Author

heddxh commented Oct 11, 2024

Have updated treesitter to latest commit.
Also updated the parser.

If this doesn't fix anything do you know if you have any custom treesitter highlights in your config?

No, this is everything about treesitter in my config.

And If I disable markdown highlight in treesitter config like highlight = { disable = {"markdown"}}, the bullet rendering is correct, even if I manually enable it by :TSBufEnable highlight. But just like above if I don't disable it in my config, only if I run :TSBufDisable highlight, it works correct. So maybe there is a race condition(just a guess, I don't have knowledge about how highlight works).

@MeanderingProgrammer
Copy link
Owner

It would seem like there's something going on with the highlights, other plugins can modify them so it's hard to know for sure what's going on. Let's look at what your highlights are just to rule that out.

First open some random markdown file.

Then run the following 2 commands to get the files containing your highlights:

:lua vim.print(vim.treesitter.query.get_files('markdown', 'highlights'))
:lua vim.print(vim.treesitter.query.get_files('markdown_inline', 'highlights'))

For me the outputs were:

{ '~/.local/share/nvim/lazy/nvim-treesitter/queries/markdown/highlights.scm' }
{ '~/.local/share/nvim/lazy/nvim-treesitter/queries/markdown_inline/highlights.scm' }

Give me the output from these commands as well as the contents of those files. This is what mine contain.

markdown/highlights.scm:

;From MDeiml/tree-sitter-markdown & Helix
(setext_heading
  (paragraph) @markup.heading.1
  (setext_h1_underline) @markup.heading.1)

(setext_heading
  (paragraph) @markup.heading.2
  (setext_h2_underline) @markup.heading.2)

(atx_heading
  (atx_h1_marker)) @markup.heading.1

(atx_heading
  (atx_h2_marker)) @markup.heading.2

(atx_heading
  (atx_h3_marker)) @markup.heading.3

(atx_heading
  (atx_h4_marker)) @markup.heading.4

(atx_heading
  (atx_h5_marker)) @markup.heading.5

(atx_heading
  (atx_h6_marker)) @markup.heading.6

(info_string) @label

(pipe_table_header
  (pipe_table_cell) @markup.heading)

(pipe_table_header
  "|" @punctuation.special)

(pipe_table_row
  "|" @punctuation.special)

(pipe_table_delimiter_row
  "|" @punctuation.special)

(pipe_table_delimiter_cell) @punctuation.special

; Code blocks (conceal backticks and language annotation)
(indented_code_block) @markup.raw.block

((fenced_code_block) @markup.raw.block
  (#set! priority 90))

(fenced_code_block
  (fenced_code_block_delimiter) @markup.raw.block
  (#set! conceal ""))

(fenced_code_block
  (info_string
    (language) @label
    (#set! conceal "")))

(link_destination) @markup.link.url

[
  (link_title)
  (link_label)
] @markup.link.label

((link_label)
  .
  ":" @punctuation.delimiter)

[
  (list_marker_plus)
  (list_marker_minus)
  (list_marker_star)
  (list_marker_dot)
  (list_marker_parenthesis)
] @markup.list

; NOTE: The following has been commented out due to issues with spaces in the
; list marker nodes generated by the parser. If those spaces ever get captured
; by a different node (e.g. block_continuation) we can safely re-add these
; conceals.
; ;; Conceal bullet points
; ([(list_marker_plus) (list_marker_star)]
;   @punctuation.special
;   (#offset! @punctuation.special 0 0 0 -1)
;   (#set! conceal "•"))
; ([(list_marker_plus) (list_marker_star)]
;   @punctuation.special
;   (#any-of? @punctuation.special "+" "*")
;   (#set! conceal "•"))
; ((list_marker_minus)
;   @punctuation.special
;   (#offset! @punctuation.special 0 0 0 -1)
;   (#set! conceal "—"))
; ((list_marker_minus)
;   @punctuation.special
;   (#eq? @punctuation.special "-")
;   (#set! conceal "—"))
(thematic_break) @punctuation.special

(task_list_marker_unchecked) @markup.list.unchecked

(task_list_marker_checked) @markup.list.checked

((block_quote) @markup.quote
  (#set! priority 90))

([
  (plus_metadata)
  (minus_metadata)
] @keyword.directive
  (#set! priority 90))

[
  (block_continuation)
  (block_quote_marker)
] @punctuation.special

(backslash_escape) @string.escape

(inline) @spell

markdown_inline/highlights.scm:

; From MDeiml/tree-sitter-markdown
(code_span) @markup.raw @nospell

(emphasis) @markup.italic

(strong_emphasis) @markup.strong

(strikethrough) @markup.strikethrough

(shortcut_link
  (link_text) @nospell)

[
  (backslash_escape)
  (hard_line_break)
] @string.escape

; Conceal codeblock and text style markers
([
  (code_span_delimiter)
  (emphasis_delimiter)
] @conceal
  (#set! conceal ""))

; Conceal inline links
(inline_link
  [
    "["
    "]"
    "("
    (link_destination)
    ")"
  ] @markup.link
  (#set! conceal ""))

[
  (link_label)
  (link_text)
  (link_title)
  (image_description)
] @markup.link.label

((inline_link
  (link_destination) @_url) @_label
  (#set! @_label url @_url))

((image
  (link_destination) @_url) @_label
  (#set! @_label url @_url))

; Conceal image links
(image
  [
    "!"
    "["
    "]"
    "("
    (link_destination)
    ")"
  ] @markup.link
  (#set! conceal ""))

; Conceal full reference links
(full_reference_link
  [
    "["
    "]"
    (link_label)
  ] @markup.link
  (#set! conceal ""))

; Conceal collapsed reference links
(collapsed_reference_link
  [
    "["
    "]"
  ] @markup.link
  (#set! conceal ""))

; Conceal shortcut links
(shortcut_link
  [
    "["
    "]"
  ] @markup.link
  (#set! conceal ""))

[
  (link_destination)
  (uri_autolink)
  (email_autolink)
] @markup.link.url @nospell

((uri_autolink) @_url
  (#offset! @_url 0 1 0 -1)
  (#set! @_url url @_url))

(entity_reference) @nospell

; Replace common HTML entities.
((entity_reference) @character.special
  (#eq? @character.special " ")
  (#set! conceal " "))

((entity_reference) @character.special
  (#eq? @character.special "<")
  (#set! conceal "<"))

((entity_reference) @character.special
  (#eq? @character.special "&gt;")
  (#set! conceal ">"))

((entity_reference) @character.special
  (#eq? @character.special "&amp;")
  (#set! conceal "&"))

((entity_reference) @character.special
  (#eq? @character.special "&quot;")
  (#set! conceal "\""))

((entity_reference) @character.special
  (#any-of? @character.special "&ensp;" "&emsp;")
  (#set! conceal " "))

You can actually see there's a NOTE in the main markdown highlights around issues concealing list marker bullets due to how the parser handles leading spaces. If your .scm or some other one added these back then I would except to see the issue you're having.

@heddxh
Copy link
Author

heddxh commented Oct 12, 2024

I think it is my colorscheme newpaper

markdown:

{ "/home/heddxh/.local/share/nvim/lazy/nvim-treesitter/queries/markdown/highlights.scm", "/home/heddxh/.local/share/nvim/lazy/newpaper.nvim/after/queries/markdown/highlights.scm" }

markdown_inline:

{ "/home/heddxh/.local/share/nvim/lazy/nvim-treesitter/queries/markdown_inline/highlights.scm", "/home/heddxh/.local/share/nvim/lazy/newpaper.nvim/after/queries/markdown_inline/highlights.scm" }

And off cource it does not comment the code like treesitter do.

;; Conceal backticks
(fenced_code_block
  (fenced_code_block_delimiter) @markup.raw.delimiter
  (#set! conceal ""))

;; Conceal bullet points
([(list_marker_plus) (list_marker_star)]
  @markup.list
  (#offset! @markup.list 0 0 0 -1)
  (#set! conceal ""))
([(list_marker_plus) (list_marker_star)]
  @markup.list
  (#any-of? @markup.list "+" "*")
  (#set! conceal ""))
((list_marker_minus)
  @markup.list
  (#offset! @markup.list 0 0 0 -1)
  (#set! conceal ""))
((list_marker_minus)
  @markup.list
  (#eq? @markup.list "-")
  (#set! conceal ""))

So is this a issue of colorscheme plugin that they should fix?

@MeanderingProgrammer
Copy link
Owner

Yeah, that seems like the culprit. It's strange for a color scheme to extend highlights, I don't think there is any way to dynamically disable them either. There might be similar issues with checkboxes based on the other highlights.

Can you try changing color schemes to validate?

Unfortunately I wouldn't call it an issue on either side as much as a conflict of interests maybe. The color scheme author probably wants to provide some nice out of the box behavior by adding these extended highlights with nothing needed from the user and that might be what most people want from it. On the flip side these highlights delve more into the rendering space and it would be unexpected behavior IMO for a color scheme to provide them. Again with no way to opt out, but that's more of a side effect with how treesitter and after directories work.

You're welcome to create an issue in the color scheme repo, get some more info, maybe mention the issue with bullet points specifically and see if they'll comment those out. But if not your options would be to use a different color scheme, not use this plugin, use this plugin but use 2 space indenting for lists otherwise you get this visual offset.

@heddxh
Copy link
Author

heddxh commented Oct 13, 2024

Thank you for your help!

@Emptyfruit
Copy link

Stumbled upon the same issue with the same Newpaper theme, which was not even in use, just installed (to use sometimes with theme switcher). I was living with weird bugs and unnecessary right_pad option for some time :) It is probably worth mentioning in the troubleshooting section of the docs )

@MeanderingProgrammer MeanderingProgrammer added not a bug Not a bug in this plugin and removed bug Something isn't working labels Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not a bug Not a bug in this plugin
Projects
None yet
Development

No branches or pull requests

3 participants