fix: resolve grammar from leading token of code fence info string - #54
Merged
veeso merged 1 commit intoJun 7, 2026
Merged
Conversation
`code.highlight` looked up the full fence info string in the languages dictionary, so a fence carrying a title or filename after the language name failed to highlight. Authors commonly write fences like `cpp:main.ino` or `cpp main.ino`, neither of which matches the bare `cpp` key. Match the full info string first so explicitly registered language names keep resolving, then fall back to the leading token (everything before the first space or `:`). Unknown leading tokens still return Error(Nil). Adds tests for the colon- and space-suffixed forms, the bare form, and an unknown language with a suffix.
|
✔️ 760ba3e - Conventional commits check succeeded. |
veeso
approved these changes
Jun 7, 2026
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
code.highlightlooks up the entire code fence info string in the languages dictionary:When an author decorates a fence with a title or filename — a common convention — the info string no longer matches a bare language key, so highlighting silently falls back to unhighlighted text:
Repro
Fix
Match the full info string first (so explicitly registered language names — including any with unusual characters — keep resolving exactly as before), then fall back to the leading token: everything before the first space or
:. An unknown leading token still returnsError(Nil), so behaviour for genuinely unsupported languages is unchanged.The split is intentionally minimal — space and
:only — matching CommonMark's "language is the text up to the first whitespace" rule plus the widespreadlang:filenameconvention. No public API changes; the two new helpers are private.Tests
Added to
test/blogatto/config/post/code_test.gleam:cpp:main.ino(colon suffix) highlightscpp main.ino(space suffix) highlightscppstill highlights (no regression)brainfuck:hello.bf(unknown leading token) still returnsError(Nil)I verified the two positive tests fail without the source change and pass with it. Full suite:
506 passed, no failures.gleam format --check src testis clean.Downstream impact
In a blog built on Blogatto, this currently forces a workaround: re-tokenising code blocks ourselves with the trimmed language after Blogatto's lookup misses. With this fix the framework's own
highlightwrapper handles decorated fences directly, letting that workaround be removed.