This documentation is also published as Markdown for efficient machine reading: the whole site is indexed at /llms.txt, and every page has a clean Markdown copy under /_llms/. These are generated from the same source and cost far fewer tokens to read than this rendered HTML.

Skip to main content Skip to navigation

FrontMatterParser Pennington.FrontMatter

Parses YAML front matter from markdown content.

Constructors

FrontMatterParser

#
public FrontMatterParser(FrontMatterParserOptions options, IHttpContextAccessor httpContextAccessor, PenningtonYamlContextProvider yaml)

Initializes the parser. Built-in front-matter types deserialize through the source-generated PenningtonYamlContext; other types fall back to reflection. Keys are camelCase matched case-insensitively. In lenient mode (the default outside build) unknown keys are dropped after a warning; in strict mode they additionally throw a YamlException.

Parameters

options FrontMatterParserOptions
Parser options controlling strict-mode behavior.
httpContextAccessor IHttpContextAccessor
Used to resolve the request-scoped DiagnosticContext.
yaml PenningtonYamlContextProvider
Supplies source-generated contexts with reflection fallback for deserialization.

FrontMatterParser

#
public FrontMatterParser()

Convenience constructor for direct instantiation (tests, scripts) that defaults to lenient mode, emits no diagnostics, and uses only the built-in serializer context. Production hosts should resolve the parser from DI so the configured FrontMatterParserOptions and any registered contexts apply.

Methods

DeserializeYaml<T>

#
public T DeserializeYaml<T>(string yaml, string sourcePath = null, DiagnosticContext diagnostics = null)

Deserialize raw YAML content (no --- delimiters) into a front matter type. Used for sidecar metadata files.

Parameters

yaml string
Raw YAML text.
sourcePath string
Source file path used in diagnostic messages. Optional.
diagnostics DiagnosticContext
Diagnostic context to receive unknown-key warnings. When omitted, the parser falls back to the per-request DiagnosticContext from IHttpContextAccessor.

Returns

T

Parse<T>

#
public FrontMatterResult<T> Parse<T>(string content, string sourcePath = null, DiagnosticContext diagnostics = null)

Parse front matter and return the metadata + remaining markdown body. Returns null metadata if no front matter block is present.

Parameters

content string
Markdown content with optional ----delimited front-matter block.
sourcePath string
Source file path used in diagnostic messages. Optional.
diagnostics DiagnosticContext
Diagnostic context to receive unknown-key warnings. When omitted, the parser falls back to the per-request DiagnosticContext from IHttpContextAccessor.

Returns

FrontMatterResult<T>

Pennington.FrontMatter.FrontMatterParser

namespace Pennington.FrontMatter;

/// Parses YAML front matter from markdown content.
public class FrontMatterParser
{
    /// Deserialize raw YAML content (no --- delimiters) into a front matter type. Used for sidecar metadata files.
    
public T DeserializeYaml<T>(string yaml, string sourcePath = null, DiagnosticContext diagnostics = null)
; /// Initializes the parser. Built-in front-matter types deserialize through the source-generated PenningtonYamlContext; other types fall back to reflection. Keys are camelCase matched case-insensitively. In lenient mode (the default outside build) unknown keys are dropped after a warning; in strict mode they additionally throw a YamlException.
public FrontMatterParser(FrontMatterParserOptions options, IHttpContextAccessor httpContextAccessor, PenningtonYamlContextProvider yaml)
; /// Convenience constructor for direct instantiation (tests, scripts) that defaults to lenient mode, emits no diagnostics, and uses only the built-in serializer context. Production hosts should resolve the parser from DI so the configured FrontMatterParserOptions and any registered contexts apply.
public FrontMatterParser()
; /// Parse front matter and return the metadata + remaining markdown body. Returns null metadata if no front matter block is present.
public FrontMatterResult<T> Parse<T>(string content, string sourcePath = null, DiagnosticContext diagnostics = null)
; }