Skip to content

feat(markdown-to-ast): add support for TOML and JSON frontmatter#2012

Merged
azu merged 3 commits into
textlint:masterfrom
3w36zj6:feature/add-support-for-toml-and-json-frontmatter-in-markdown-parsing
Apr 26, 2026
Merged

feat(markdown-to-ast): add support for TOML and JSON frontmatter#2012
azu merged 3 commits into
textlint:masterfrom
3w36zj6:feature/add-support-for-toml-and-json-frontmatter-in-markdown-parsing

Conversation

@3w36zj6

@3w36zj6 3w36zj6 commented Apr 26, 2026

Copy link
Copy Markdown
Member

close #2006

Changes

This PR adds support for TOML and JSON frontmatter to the markdown-to-ast package.

TOML

Similar to YAML, micromark-extension-frontmatter supports TOML by default via its presets1. Therefore, we simply need to enable TOML in remark-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-frontmatter lacks 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

---
{
    "title": "My Article Title",
    "date": "2024-01-15",
    "author": "John Doe",
    "tags": ["markdown", "tutorial", "web"]
}
---

# Article Content

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 Content

Hugo5

{
    "title": "My Article Title",
    "date": "2024-01-15",
    "author": "John Doe",
    "tags": ["markdown", "tutorial", "web"]
}

# Article Content

Hexo6

;;;
"title": "My Article Title",
"date": "2024-01-15",
"author": "John Doe",
"tags": ["markdown", "tutorial", "web"]
;;;

# Article Content

Footnotes

  1. https://github.com/micromark/micromark-extension-frontmatter/blob/727a56e89c80e9829b3d6bb2a1bca9ec21630c84/dev/lib/to-matters.js#L8

  2. https://github.com/eslint/markdown/issues/404

  3. https://vitepress.dev/guide/frontmatter#alternative-frontmatter-formats

  4. https://www.11ty.dev/docs/data-frontmatter/#json-front-matter

  5. https://gohugo.io/content-management/front-matter/

  6. https://www.npmjs.com/package/hexo-front-matter

Copilot AI review requested due to automatic review settings April 26, 2026 10:10

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: "}" } }
])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Front matter

This looks fine.

@azu azu added the Type: Feature New Feature label Apr 26, 2026

@azu azu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks

@azu azu merged commit f14e25a into textlint:master Apr 26, 2026
13 checks passed
@github-actions github-actions Bot mentioned this pull request Apr 26, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Feature New Feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detect json & toml frontmatter node types

3 participants