类 MarkdownParser

java.lang.Object
com.agentsflex.skill.util.MarkdownParser

public class MarkdownParser extends Object
Parser for Markdown documents with optional YAML front matter.

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
  • 字段详细资料

    • frontMatter

      Map containing the parsed front matter key-value pairs.
    • content

      private String content
      The content of the markdown document (everything after the front matter).
  • 构造器详细资料

    • MarkdownParser

      public MarkdownParser(String markdown)
      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

      private void parseFrontMatter(String frontMatterSection)
    • removeQuotes

      private String removeQuotes(String value)
    • 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

      public String 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