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
optionsFrontMatterParserOptions- Parser options controlling strict-mode behavior.
httpContextAccessorIHttpContextAccessor- Used to resolve the request-scoped
DiagnosticContext. yamlPenningtonYamlContextProvider- 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
yamlstring- Raw YAML text.
sourcePathstring- Source file path used in diagnostic messages. Optional.
diagnosticsDiagnosticContext- Diagnostic context to receive unknown-key warnings. When omitted, the parser falls back to the per-request
DiagnosticContextfromIHttpContextAccessor.
Returns
TParse<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
contentstring- Markdown content with optional
----delimited front-matter block. sourcePathstring- Source file path used in diagnostic messages. Optional.
diagnosticsDiagnosticContext- Diagnostic context to receive unknown-key warnings. When omitted, the parser falls back to the per-request
DiagnosticContextfromIHttpContextAccessor.
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)
;
}