类 MarkdownParser
This parser extracts YAML front matter (metadata) and content from Markdown documents. Front matter is delimited by triple dashes (---) at the beginning of the document and contains key-value pairs in YAML format.
Example Markdown with front matter:
---
title: My Document
author: John Doe
date: 2024-01-15
---
# Heading
Document content here.
The parser supports:
- Front matter with key-value pairs separated by colons
- Values with or without quotes (both single and double quotes are supported)
- Documents without front matter (entire content is treated as body)
- Empty or null markdown input
- 作者:
- Christian Tzolov
-
字段概要
字段 -
构造器概要
构造器构造器说明MarkdownParser(String markdown) Constructs a new MarkdownParser and parses the provided markdown content. -
方法概要
修饰符和类型方法说明Returns the content portion of the markdown document.Returns a copy of the parsed front matter as a map.private voidparseFrontMatter(String frontMatterSection) private StringremoveQuotes(String value)
-
字段详细资料
-
frontMatter
Map containing the parsed front matter key-value pairs. -
The content of the markdown document (everything after the front matter).
-
-
构造器详细资料
-
MarkdownParser
Constructs a new MarkdownParser and parses the provided markdown content. Parses the markdown content to extract front matter and body content.Front matter must start with "---" at the beginning of the document and end with another "---". Everything between these delimiters is parsed as front matter. Everything after the closing delimiter is treated as content.
- 参数:
markdown- the markdown string to parse, may contain front matter delimited by triple dashes (---). Can be null or empty.
-
-
方法详细资料
-
parseFrontMatter
-
removeQuotes
-
getFrontMatter
Returns a copy of the parsed front matter as a map.The returned map contains all key-value pairs extracted from the front matter section. If no front matter was present or the input was null/empty, returns an empty map.
- 返回:
- a new map containing the front matter key-value pairs
-
getContent
Returns the content portion of the markdown document.This is everything after the closing front matter delimiter (---), with leading and trailing whitespace trimmed. If no front matter was present, returns the entire document. If the input was null or empty, returns an empty string.
- 返回:
- the markdown content as a string
-