Closed ikalnytskyi closed 2 years ago
In nvim-treesitter this is done by querying content between two consecutive thematic breaks, but this is of course not very accurate and stable. So this seems like a good idea.
Last time I tried nvim-treesitter, front-matter wasn't supported. 🤔 Are you saying that I can have a query that is not tied to AST elements? I.e. just simply check for --- at the beginning and make an injection for this?
Yes kind of. In realtiy it checks for thematic breaks, so it doesn't work to great. You can see the query in nvim-treesitter here. To use this you may need to update nvim-treesitter of course.
I have noticed that the neovim treesitter query works if there is an extra space at the end of the frontmatter. here is an example
https://user-images.githubusercontent.com/5523984/156380005-4f38dbb9-9a34-4ec3-98ae-d8b81af8f72e.mov
This is implemented in the newest version. (Update the nvim-treesitter plugin and run :TSUpdate
to get the newest version)
Currently both pluses and minuses cause the content to be parsed as YAML as that is the behavior. I'm not sure why, probably because I made a mistake writing the query.
It's easy to fix with :TSEditQueryUserAfter injections markdown
though and someone motivated could open a PR to nvim-treesitter
Rationale
Markdown is a quite popular choice for writing content for static sites or documentation. Majority of existing tooling supports so called "front matter" that allows to attach some metadata to the document.
See example https://gohugo.io/content-management/front-matter/
Suggestion
Front matter is neither a part of the standard nor standardize among existing tooling. Nevertheless, it seems community pretty much settled on two front matter formats:
YAML is used in case of
---
separator. E.g:TOML is used in case of
+++
separator. E.g:It would be nice to support both YAML and TOML injections for this 2 most popular choices. I'm sure it would cover 99% of cases.