Skip to content
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

Feature request: add front matter support #32

Closed
ikalnytskyi opened this issue Feb 8, 2022 · 6 comments
Closed

Feature request: add front matter support #32

ikalnytskyi opened this issue Feb 8, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@ikalnytskyi
Copy link

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:

    ---
    tags: [foo, bar]
    summary: a short summary
    ---
    
    # My blog post
    
    ...
  • TOML is used in case of +++ separator. E.g:

    +++
    tags = ["foo", "bar"]
    summary = "a short summary"
    +++
    
    # My blog post
    
    ...

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.

@MDeiml
Copy link
Collaborator

MDeiml commented Feb 9, 2022

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.

@MDeiml MDeiml added the enhancement New feature or request label Feb 9, 2022
@ikalnytskyi
Copy link
Author

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?

@MDeiml
Copy link
Collaborator

MDeiml commented Feb 11, 2022

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.

@mhanberg
Copy link

mhanberg commented Mar 2, 2022

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

Screen.Recording.2022-03-02.at.9.21.49.AM.mov

@MDeiml
Copy link
Collaborator

MDeiml commented Jul 19, 2022

This is implemented in the newest version. (Update the nvim-treesitter plugin and run :TSUpdate to get the newest version)

@MDeiml MDeiml closed this as completed Jul 19, 2022
@MDeiml
Copy link
Collaborator

MDeiml commented Jul 19, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants