Add FrontmatterExtension for parsing document metadata#122
Merged
dereuromark merged 3 commits intomasterfrom Mar 24, 2026
Merged
Add FrontmatterExtension for parsing document metadata#122dereuromark merged 3 commits intomasterfrom
dereuromark merged 3 commits intomasterfrom
Conversation
Implements frontmatter support as a pure extension without core changes.
Uses ---format syntax (e.g., ---yaml, ---toml, ---json) to distinguish
from thematic breaks (---).
Features:
- Parses frontmatter at document start only
- Supports optional djot attributes: ---yaml {.meta key="value"}
- Format-agnostic: raw content accessible for parsing with any library
- Configurable rendering: hidden (default), HTML comment, or custom callback
- getParsedContent() helper for easy integration with yaml/toml/json parsers
Based on discussion in jgm/djot#35 and tree-sitter-djot grammar approach.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #122 +/- ##
============================================
+ Coverage 93.83% 93.92% +0.08%
- Complexity 2369 2382 +13
============================================
Files 79 81 +2
Lines 6261 6303 +42
============================================
+ Hits 5875 5920 +45
+ Misses 386 383 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Open
There was a problem hiding this comment.
Pull request overview
Adds a new Djot extension to recognize and expose document-start frontmatter blocks (YAML/TOML/JSON/etc.) using a ---format opener to avoid clashing with thematic breaks, plus documentation and PHPUnit coverage.
Changes:
- Introduces
FrontmatterExtensionto parse---format ... ---blocks at document start and expose raw content/format/attributes. - Adds a
Frontmatterblock node type and render controls (hidden by default, HTML comment, or custom callback). - Adds user-facing docs and a comprehensive test suite for the new extension behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/Extension/FrontmatterExtension.php |
Implements the frontmatter block pattern, state storage, and render-time output handling. |
src/Extension/Frontmatter.php |
Adds a new block node type to represent parsed frontmatter in the AST. |
tests/TestCase/Extension/FrontmatterExtensionTest.php |
Adds PHPUnit tests for parsing, rendering options, attributes, and helper methods. |
docs/extensions/index.md |
Documents FrontmatterExtension usage, options, and syntax. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Auto-clear state between convert() calls (no need for manual reset()) - Make format non-nullable (always provided in ---format syntax) - Return null for unclosed frontmatter (missing closing ---) - Add missing use statements in documentation examples - Document that attributes must be inline (not on preceding line) - Add tests for unclosed frontmatter and extension reuse scenarios
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.
Summary
FrontmatterExtensionfor parsing YAML/TOML/JSON frontmatter at document start---formatsyntax (e.g.,---yaml,---toml) to distinguish from thematic breaks---yaml {.meta key="value"}Based on discussion in jgm/djot#35 and the tree-sitter-djot grammar approach.
Usage
Features
---python {kernel="myproject" #cell-1}getParsedContent()helper for easy integrationOut of scope
Use cases for multiple blocks:
But that could be its own custom extension if needed.