Skip to content

Better YAML front matter parsing in commonmark-ext-yaml-front-matter - #445

Open
zyxist wants to merge 1 commit into
commonmark:mainfrom
zyxist:yaml-front-matter-extractors
Open

Better YAML front matter parsing in commonmark-ext-yaml-front-matter#445
zyxist wants to merge 1 commit into
commonmark:mainfrom
zyxist:yaml-front-matter-extractors

Conversation

@zyxist

@zyxist zyxist commented Aug 1, 2026

Copy link
Copy Markdown

Last year, I reported the issue #391 - I found some time to turn it into the contribution, based on the outcome of the discussion. I will be happy to discuss the approach and apply any improvements, if necessary.

Summary

The PR splits the YAML front matter processing into two parts:

  1. Finding front matter delimiters
  2. Processing the captured front matter content with the new concept of YamlFrontMatterExtractor.

I moved the existing built-in parser of YAML subset into one of the two extractors: YamlDataExtractor. The other extractor is YamlContentExtractor that extracts the front matter as a string for further processing with other tools.

Compatibility

The changes are backward-compatible. YamlDataExtractor is the default extractor, and one must explicitly initialize the extension with YamlContentExtractor to get the string content. The visitor and Markdown renderer support both modes.

Naming

For the existing parser, I strived to keep consistent naming to help understand the connection: YamlFrontMatterVisitor.getData() (existing method) => YamlDataExtractor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant