String Utilities 工具已更新 2 天前

Markdown Front Matter Extractor

Split a Markdown file into its YAML front matter and its body. Paste the file and press Extract: the server parses the metadata into JSON and returns the raw YAML, the content without front matter, and a combined JSON result you can copy or download as markdown-front-matter.json.

永久免费 易于使用 立竿见影的效果 私密且安全

使用 Markdown Front Matter Extractor

Markdown 前置信息提取器

从文档中提取 YAML 前置信息、已解析的元数据以及干净的 Markdown 内容。

输入 Markdown

粘贴可能以 YAML 前置信息开头的 Markdown 代码
前言部分以以下内容开头: --- 位于第一行,并以另一个 ---.
无前言
检测状态
0 键
元数据字段

提取结果

元数据、原始 YAML、内容和完整的 JSON
复制内容
复制完整 JSON
前言提示
此工具适用于博客文章、文档页面、静态网站内容、变更日志以及带有 YAML 元数据的文件。

阅读内容

了解该工具的工作原理以及何时使用它。

Separate YAML metadata from the body of a Markdown file

Static site generators and content platforms such as Jekyll, Hugo, Eleventy, Astro, Docusaurus and many headless CMS tools store page settings at the top of each Markdown file in a block called front matter. It holds the title, date, author, tags, slug, draft flag and anything else the site needs. The Markdown Front Matter Extractor splits a file into its two halves: the YAML metadata, parsed into JSON, and the Markdown content with the front matter removed. Both are shown separately so you can copy whichever part you need.

What front matter looks like

A typical file starts like this:

---
title: Getting started
date: 2024-01-15
tags: [setup, install]
draft: false
---
# Getting started

The opening --- must be the very first line of the file and the block ends at the next line that is exactly ---. Everything in between is read as YAML.

What the result contains

After extraction, the Extracted Result card shows five fields:

FieldContents
has_front_mattertrue when a valid front matter block was found, otherwise false
metadata JSONThe YAML parsed into a JSON object, for example {"title": "Getting started", "draft": false}
raw_front_matterThe YAML text exactly as written, without the --- lines
content without front matterThe Markdown body, with leading blank lines removed
full JSONhas_front_matter, metadata, raw front matter and content combined in one JSON object

Two status cards summarise the result: Detection status shows "Front matter found" or "No front matter", and Metadata fields counts the top-level keys. The footer reports the size of the full JSON and the word count of the content.

How to extract front matter

  1. Paste a Markdown file into Input Markdown, or press Paste in the header. The footer shows its character and line counts.
  2. Press Extract. The button shows "Working" while the request is processed.
  3. Check Detection status. If it says "No front matter", read the troubleshooting tips below.
  4. Copy the part you need: Copy Raw YAML for the original metadata block, Copy Content for the body only, or Copy Full JSON for everything.
  5. Press Download JSON to save the full result as markdown-front-matter.json.

Copy Input copies your original text, and Clear resets the input and all result fields.

Server-side parsing

The YAML is parsed on this site's server with the Symfony YAML component, a widely used PHP parser. When you press Extract, your Markdown is sent to the server, split and parsed there, and the result is returned to your browser. Input is limited to 200,000 characters per request; larger files are rejected with an error. Do not paste files that contain secrets such as API keys in their front matter.

How YAML values come out in JSON

Most values convert the way you would expect: strings stay strings, true and false become booleans, numbers become numbers, lists become arrays and nested keys become nested objects. One case needs attention:

  • Unquoted dates become numbers. The parser turns a bare date such as date: 2024-01-15 into a Unix timestamp, so the metadata JSON shows 1705276800 instead of the date text. If you need the date as written, put it in quotes in your YAML, date: "2024-01-15", or read it from the raw front matter field, which always keeps the original text.

If the YAML has a syntax error, for example a bad indent or an unclosed quote, the block is still detected and raw_front_matter still holds the text, but the metadata JSON is left empty. That combination, "Front matter found" with 0 keys, is a reliable sign of invalid YAML.

Where this saves time

  • Migrating between site generators. Pull the metadata out of each post so you can map fields from one platform's naming to another.
  • Feeding a CMS or database. The full JSON is easy to import, with metadata and body already separated.
  • Checking a post before publishing. Confirm the title, tags and draft flag parse the way your site generator will read them.
  • Cleaning content for reuse. Copy the body without front matter to paste into an editor, an email or a word counter.
  • Debugging build errors. When a static site build fails on one file, the empty metadata result quickly shows whether the YAML is at fault.

Troubleshooting "No front matter"

  • Make sure the very first characters of the file are --- followed by a line break. A blank line, a space or an invisible byte order mark before it prevents detection.
  • Make sure the closing --- sits on its own line and is followed by a line break. A file that ends immediately after the closing dashes, with nothing after them, is not detected; add a newline or a line of content.
  • Use three hyphens. TOML front matter between +++ lines and JSON front matter are not supported.
  • An empty block with nothing between the two --- lines is not detected.

Raw YAML or parsed JSON: which to copy

Copy the raw YAML when you are moving a post to another YAML-based site generator, because it keeps comments, quoting and key order exactly as written. Copy the metadata JSON, or the full JSON, when the destination is a script, an API or a database that expects structured data. If the two disagree, for example a date that turned into a number, trust the raw YAML as the record of what the author wrote.

Things to avoid

  • Do not rely on the metadata JSON for unquoted dates; use the raw YAML or quote the value.
  • Do not assume the content field is untouched: leading blank lines after the front matter are trimmed.
  • Do not paste confidential configuration. The text is processed on the server.
  • Do not expect the tool to fix YAML. It reports what parses and keeps the raw text; correcting errors is up to you.

Limitations

  • YAML front matter only, delimited by --- at the very top of the file.
  • Invalid YAML produces empty metadata rather than an error message pointing to the problem line.
  • Unquoted dates are converted to Unix timestamps in the metadata JSON.
  • Input is capped at 200,000 characters and needs a network connection.
  • One file at a time; there is no batch mode.

Related tools

To create a new front matter block from form fields rather than read one, use the Markdown Metadata Generator. To list the headings in the body you just extracted, try the Markdown Heading Extractor.

Frequently Asked Questions

常见问题解答

针对用户在信任结果之前常提出的疑问,提供简短解答。

YAML front matter between two lines of three hyphens at the very top of the file. TOML front matter with plus signs and JSON front matter are not supported.

The YAML parser converts unquoted dates into Unix timestamps. Quote the date in your YAML, or copy it from the raw front matter field, which keeps the original text.

The YAML could not be parsed, usually because of a wrong indent, a tab character or an unclosed quote. The raw YAML is still shown so you can find and fix the problem.

The first line must be exactly three hyphens with nothing before it, and the closing three hyphens must be followed by a line break. Blank lines, spaces or a byte order mark at the top stop detection.

No. The Markdown is sent to this site's server, where the YAML is parsed, and the result is returned to your browser.

Yes. Each request can contain up to 200,000 characters. Larger input is rejected with an error message.

The file markdown-front-matter.json holds has_front_matter, the parsed metadata, the raw front matter text and the content without front matter.

评论 (0)

用于用户讨论、边界情况及后续建议。
发表评论
您的评论提交后将公开展示。
目前尚无评论。快来发表第一条评论吧!
请告诉我们!
报告此工具的问题

请描述您遇到的问题,以便我们进行调查并改进该工具。

什么最有帮助
请提供输入内容、预期结果、实际结果、浏览器/设备信息,如有帮助,请附上截图。
“截图”按钮会截取浏览器中的页面,并将生成的图片作为附件添加到此表单中。
整页截图
通过 newisty 在您的浏览器中捕获。
尚未截取屏幕截图。
工具 报告