tree-sitter-grammars / tree-sitter-markdown

Markdown grammar for tree-sitter
MIT License
414 stars 52 forks source link

Missing headings level names #37

Closed keiviv closed 2 years ago

keiviv commented 2 years ago

The headings level names are missing:

Heading      Default      Treesitter
-----------------------------------------
  # Level 1  markdownH1   markdownTSTitle
 ## Level 2  markdownH2   markdownTSTitle
### Level 3  markdownH3   markdownTSTitle
...
-----------------------------------------

Implementing the levels would significantly improve the readability via color schemes. This module is amazing, and the H levels would make it even more spectacular. ❤️

clason commented 2 years ago

This is more of a limitation of nvim-treesitter, which does not offer enough captures (and highlight groups) to distinguish them, even if there's a node for it.

(Nvim-treesitter is more centralized than legacy regex syntax highlighting, where every language was allowed to define whatever highlight groups it wanted without concern for others. While this leads to a more consistent highlighting for standard programming languages, it restricts the possibilities for other types of languages.)

MDeiml commented 2 years ago

Exactly, the level names are actually emitted as nodes. But if you want you add custom highlight captures as described in the nvim-treesitter README. E.g. add

[
  (atx_heading
    (atx_h1_marker))
  (setext_heading
    (setext_h1_underline))
] @text.title1

to markdowns highlights.scm and

lua <<EOF
  require"nvim-treesitter.highlight".set_custom_captures {
    ["text.title1"] = "markdownH1",
  }
EOF

to your config.