Skip to content

support frontmatter syntax #264

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

m4rch3n1ng
Copy link
Contributor

fixes #253
fixes #224

this parses rust frontmatter as specified in rfc 3503. like with raw strings (which this implementation takes quite a bit of inspiration from), the frontmatter content is parsed as a seperate node (frontmatter_content) to allow, for example, to add a toml language injection for the content.

i had to do a little hack because of tree-sitter automatically stripping all whitespace, meaning that i cannot always rely on having a newline before the ending fence. this means that it will incorrectly parse some things, but i think those are edge cases that are acceptable, because i couldn't figure out a way to make it stop stripping all whitespace between _frontmatter_start and frontmatter_content (which is also the cause for #251):

// this is technically valid rust and rustc doesn't consider the indented line
// as the ending fence, but instead the third line, while this pr already bails on the second line.
---
  ---
---

fn main() {}

no diff for rustc tests as rustc support for it is not yet merged.

@wetneb
Copy link

wetneb commented Jun 4, 2025

This PR is also integrated in the tree-sitter-rust-orchard fork. See #271 (comment) for context.

@nik-rev
Copy link

nik-rev commented Jun 11, 2025

I suggest making the "Info String" a separate node, similar to how it is in markdown. so you can match against it like

(info_string "yaml")

To inject the "yaml" language for example.

@m4rch3n1ng
Copy link
Contributor Author

that is actually surprisingly hard, as that is whitespace-sensitive (an "--- info string" should parse differently than a "---\ninfo string" and the tree-sitter-rust grammer automatically strips all whitespace between nodes, see:

i have a kinda-working prototype, but that one doesn't work for incremental parsing. i'll try again later to get it actually working, but don't get your hopes up lol.

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

Successfully merging this pull request may close these issues.

feature: frontmatter syntax support feature: frontmatter
3 participants