Skip to content

help: How do I make setext headers go away? #381

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
Asterikss opened this issue Mar 28, 2025 · 6 comments
Closed

help: How do I make setext headers go away? #381

Asterikss opened this issue Mar 28, 2025 · 6 comments
Labels
question Further information is requested

Comments

@Asterikss
Copy link

Neovim version (nvim -v)

0.10.0

Neovim distribution

N/A

Description

Relevant configuration:

opts = {
  render_modes = true,
  anti_conceal = {
    enabled = false,
  },
}

This happens when I try to write nested bullet points:

2025-03-28.17-01-15.mp4

Source just in case:

- test:
  - 

I couldn't successfully change / find anything related in the available configuration.

How do I turn this off? I'm really only interested in the - character not triggering it. Other characters are fine. Can I change the character that triggers it or turn this rendering off completely somehow?

@Asterikss Asterikss added the question Further information is requested label Mar 28, 2025
@MeanderingProgrammer
Copy link
Owner

You can't change the definition of a setext header through this plugin, that just comes from the treesitter parser, which this plugin relies on.

Looking at the common mark spec the implementation seems to be correct, even in github you'll see that the text:

- test:
  - 

Renders as a setext header:

  • test:

What I can do is add a way to disable rendering setext headers as part of this plugin, but that would apply universally. Most people don't use those style of headers anyway so probably not much of a loss, would that help?

@Asterikss
Copy link
Author

Yes, that'd be great!

MeanderingProgrammer added a commit that referenced this issue Mar 31, 2025
## Details

Request: #381

Adds `heading.atx` and `heading.setext` boolean options. These let you
disable rendering for a specific subset of heading types rather than an
all or nothing. By default both remain enabled. Mostly helpful for
`setext` headings since their syntax can overlap with nested lists.
@MeanderingProgrammer
Copy link
Owner

Added the feature, can now disable setext headings with { heading = { setext = false } }

@Asterikss
Copy link
Author

It did remove the foreground, background, and cursor jump, which is awesome. However, it is still being highlighted as a
heading2.

This is, again, not related to the plugin per se. Is this feasible to change (as an option through the plugin, similar to rendering setext)?

2025-04-01.00-05-44.mp4
2025-04-01.00-34-01.mp4

Both recordings were made with render-markdown.nvim disabled.

This is also the case when I did not install markdown and markdown_inline parsers via nvim-treesitter.

Again, is it possible to change this (remove the text highlight) without messing up the standard atx headings?"

@MeanderingProgrammer
Copy link
Owner

This is, again, not related to the plugin per se. Is this feasible to change (as an option through the plugin, similar to rendering setext)?

It is not. The plugin not doing something it is doing is easy, so I added the option.

Highlighting on the other hand is completely unrelated to this plugin and just comes from treesitter. Neovim itself comes bundled with the markdown parser & highlights, so it's not dependent on nvim-treesitter.

In order to accomplish what you want, at least as far as I know, the only way is to override the highlights completely in your own configuration.

So create a file at: <config_root>/queries/markdown/highlights.scm

Set the contents to be a copy of the nvim-treesitter highlights, minus the bits related to setext_heading. If you're going to do this I would also remove the conceal / conceal_lines directives around fenced code blocks since changing the default highlights will mess with how this plugin disables them in 0.11.0.

So in this case you would end up with:

; nvim-treesitter highlights minus:
;   setext headings
;   concealing around code blocks (handled by render-markdown.nvim)

(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

(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)

(fenced_code_block
  (info_string
    (language) @label))

(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

(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

While this will remove highlighting for setext headings it still won't change the fact that it is recognized as a setext heading, so the - on the second line will not be rendered as a list item, since it is not a list item. Doing this or any other such modification requires changes to the actual parser which I do not have control over.

@Asterikss
Copy link
Author

I understand. Thank you very much for your help!


If anyone stumbles upon it:

(This is not needed or simpler if one sets only one scope_highlight or none at all for bullet points)

I tried a few things. I ended up setting these:

(setext_heading
  (paragraph) @markup.heading.1
  (setext_h1_underline) @markup.heading.1)

(setext_heading
 (paragraph) @custom.setex.heading.2
 (setext_h2_underline) @custom.setex.underline.2)

And I manually set the @custom.setex.heading.2 highlight to the bullet point highlight being 'overshadowed' (first level) and @custom.setex.underline.2 to the color that the 'below' bullet should have (second-level bullet).

This is needed too:

heading = {
  setext = false,
},

Those also keep setex1 headings (created using =) (without render-markdown overlay, obviously).

Only removing setex headings:
Image

Final result:
Image

With a caveat that it only takes care of the first-level parent bullet highlight (fixing that would indeed require patching the parser/grammar I think) (and also it will not render the bullet icon, irrespective of the level):
Image

Also a keymap can be used specifically for the creation of nested bullet points that uses a + instead, which eventually gets hidden with anti_conceal and general conceal behaviour, so that highly suboptimal keyboard layout changes do not need to be made to switch fully to using + everywhere heh.

vim.api.nvim_buf_set_keymap(0, 'i', ';', '<End>:<CR><TAB>+ ', { noremap = true })

Thank you again for helping!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants