feat(markdown-to-ast): add support for TOML and JSON frontmatter#2012
Merged
azu merged 3 commits intoApr 26, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds TOML and JSON frontmatter parsing support to @textlint/markdown-to-ast, so TOML/JSON frontmatter blocks are recognized as dedicated AST nodes (instead of being parsed as normal paragraphs), addressing #2006.
Changes:
- Enable TOML frontmatter in the remark parser configuration.
- Add custom JSON frontmatter markers to support several common dialects (11ty/Hexo/Hugo; VitePress remains YAML-fenced).
- Extend the markdown syntax mapping and add new parsing fixtures for TOML/JSON frontmatter outputs.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/@textlint/markdown-to-ast/src/parse-markdown.ts | Enables TOML frontmatter and introduces custom JSON frontmatter fence markers. |
| packages/@textlint/markdown-to-ast/src/mapping/markdown-syntax-map.ts | Maps toml/json mdast node types to Toml/Json textlint node types. |
| packages/@textlint/markdown-to-ast/test/fixtures/frontmatter-toml.text/input.md | New TOML frontmatter fixture input. |
| packages/@textlint/markdown-to-ast/test/fixtures/frontmatter-toml.text/output.json | Expected AST output for TOML frontmatter. |
| packages/@textlint/markdown-to-ast/test/fixtures/frontmatter-json-vitepress.text/input.md | New VitePress-style JSON-in---- fixture input. |
| packages/@textlint/markdown-to-ast/test/fixtures/frontmatter-json-vitepress.text/output.json | Expected AST output (parsed as Yaml) for VitePress-style markers. |
| packages/@textlint/markdown-to-ast/test/fixtures/frontmatter-json-11ty.text/input.md | New 11ty ---json fixture input. |
| packages/@textlint/markdown-to-ast/test/fixtures/frontmatter-json-11ty.text/output.json | Expected AST output for 11ty JSON frontmatter. |
| packages/@textlint/markdown-to-ast/test/fixtures/frontmatter-json-hugo.text/input.md | New Hugo { ... } fixture input. |
| packages/@textlint/markdown-to-ast/test/fixtures/frontmatter-json-hugo.text/output.json | Expected AST output for Hugo-style JSON frontmatter. |
| packages/@textlint/markdown-to-ast/test/fixtures/frontmatter-json-hexo.text/input.md | New Hexo ;;; fixture input. |
| packages/@textlint/markdown-to-ast/test/fixtures/frontmatter-json-hexo.text/output.json | Expected AST output for Hexo-style JSON frontmatter. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+17
to
+26
| .use(frontmatter, [ | ||
| "yaml", | ||
| "toml", | ||
| // Hexo style | ||
| { type: "json", fence: { open: ";;;", close: ";;;" } }, | ||
| // 11ty style | ||
| { type: "json", fence: { open: "---json", close: "---" } }, | ||
| // Hugo style | ||
| { type: "json", fence: { open: "{", close: "}" } } | ||
| ]) |
…tmatter-in-markdown-parsing
Merged
azu
added a commit
that referenced
this pull request
Apr 26, 2026
<!-- Release notes generated using configuration in .github/release.yml at master --> ## What's Changed ### Features * feat(markdown-to-ast): add support for TOML and JSON frontmatter by @3w36zj6 in #2012 ### CI * fix(ci): remove CNAME from website PR preview build by @azu in #1999 * chore(deps): update github/codeql-action action to v3.35.2 by @renovate[bot] in #2010 * Update merge-gatekeeper action and add actions permission by @azu in #2014 ### Dependency Updates * chore(deps): update docusaurus monorepo to ^3.10.0 (minor) by @renovate[bot] in #2000 * chore(deps): update dependency oxlint to ^1.59.0 by @renovate[bot] in #2002 * chore(deps): update patch updates (patch) by @renovate[bot] in #2001 * chore(deps): update dependency oxlint-tsgolint to ^0.20.0 by @renovate[bot] in #2004 * chore(deps): update dependency json5 to ^2.2.3 by @renovate[bot] in #2003 * chore(deps): update react monorepo to ^19.2.5 (patch) by @renovate[bot] in #2005 * chore(deps): update dependency oxlint-tsgolint to ^0.21.0 by @renovate[bot] in #2007 * chore(deps): update dependency oxlint-tsgolint to ^0.21.1 by @renovate[bot] in #2009 * chore(deps): update pnpm to v10.33.1 by @renovate[bot] in #2011 * chore(deps): update pnpm to v10.33.2 by @renovate[bot] in #2013 ### Other Changes * fix(website): move onBrokenMarkdownLinks into markdown.hooks by @azu in #1998 **Full Changelog**: v15.5.4...v15.6.0 Co-authored-by: azu <azu@users.noreply.github.com>
1 task
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.
close #2006
Changes
This PR adds support for TOML and JSON frontmatter to the
markdown-to-astpackage.TOML
Similar to YAML,
micromark-extension-frontmattersupports TOML by default via its presets1. Therefore, we simply need to enable TOML inremark-frontmatter.JSON
I wasn't entirely sure about the JSON frontmatter specifications, so I looked into it. It turns out there are several dialects across different tools like VitePress, 11ty, Hugo, and Hexo2. This is likely why
remark-frontmatterlacks a predefined marker for JSON.In this PR, I have added support for what I consider to be the major formats by setting up custom markers.
VitePress3
In the textlint AST, this is parsed as YAML. However, since textlint doesn't officially target YAML nodes for linting, I believe this won't cause any immediate issues. It is also possible to check if the YAML content can be parsed as JSON and convert it into a JSON node during a post-processing step.
11ty4
---json { "title": "My Article Title", "date": "2024-01-15", "author": "John Doe", "tags": ["markdown", "tutorial", "web"] } --- # Article ContentHugo5
{ "title": "My Article Title", "date": "2024-01-15", "author": "John Doe", "tags": ["markdown", "tutorial", "web"] } # Article ContentHexo6
Footnotes
https://github.com/micromark/micromark-extension-frontmatter/blob/727a56e89c80e9829b3d6bb2a1bca9ec21630c84/dev/lib/to-matters.js#L8 ↩
https://github.com/eslint/markdown/issues/404 ↩
https://vitepress.dev/guide/frontmatter#alternative-frontmatter-formats ↩
https://www.11ty.dev/docs/data-frontmatter/#json-front-matter ↩
https://gohugo.io/content-management/front-matter/ ↩
https://www.npmjs.com/package/hexo-front-matter ↩