Repository navigation
Fix GitHub highlighting of .cook files with YAML front matter - #30
Merged
Merged
Conversation
…ghts the body On github.com, any .cook file whose front matter contains a mapping or a list item (`title: X`, `- tag`) rendered the whole recipe body as YAML: text before a colon became a YAML key, `#cookware` became a YAML comment, and no ingredients, cookware, timers or sections were highlighted. The front matter rule used begin/while. GitHub's highlighter does not end a `while` rule while a nested rule from the included YAML grammar is still open, so the block never closed. Plain begin/end, the shape GitHub's own Markdown grammar uses for front matter, closes correctly there. In VS Code the only token change is that the closing `---` / `...` line now gets `punctuation.definition.frontmatter.end.cooklang`. Claude-Session: https://claude.ai/code/session_01B7jPFQJPPhZyUuGSiAsq2f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
GitHub highlights
.cookfiles with this repo's grammar, which Linguist vendors assource.cooklang. On github.com, any recipe whose front matter has a mapping or a list item renders the whole body as YAML:Mix the dry ingredients: @flour{200%g}) becomes a YAML key;#potlines become YAML comments;== sections ==are highlighted.Since almost every real recipe has
title:/tags:front matter, this hits most.cookfiles on GitHub. VS Code is not affected.Cause
The front matter rule was
begin/while. On GitHub's highlighter, checked live through the/markdownAPI with a```cooklangfence:---foo), or commenta: b,a:) or list item (- x)...instead of---The included YAML grammar opens a multi-line rule for mappings and lists. GitHub doesn't end the outer
whilerule while that nested rule is still open, so the block never closes. VS Code checks everywhileon the rule stack at the start of each line, which is why it works there.Fix
Use plain
begin/end:begin: \A-{3}\s*$,end: ^(-{3}|\.{3})\s*$. Theendmatch consumes the closing line. This is the same shape GitHub's own Markdown grammar (wooorm/markdown-tm-language) uses around the samesource.yaml. Through the live API, that shape closes correctly after mappings, nested lists,|and>block scalars as the last key, and an open[a,flow list.Effect in VS Code
I ran
vscode-textmatewith VS Code's built-in YAML grammar over 11 sample files covering empty front matter,...closing, nested lists, block scalars, open flow collections, unclosed quotes and no front matter. The only token change is that the closing---/...line now getspunctuation.definition.frontmatter.end.cooklang. Front matter and body tokens are identical.Known limitation
With GitHub's YAML grammar (
atom/language-yaml), an unclosed quote in front matter (title: "Pie) still runs past the closing---. GitHub's Markdown front matter has the same limitation, and that front matter isn't valid YAML anyway.When it shows on github.com
Linguist pins this repo's
mainand picks up grammar changes at its next release (see Linguist's CONTRIBUTING, "Fixing syntax highlighting"). No Linguist PR is needed.https://claude.ai/code/session_01B7jPFQJPPhZyUuGSiAsq2f