app.domain.frontmatter¶
YAML frontmatter splitting and loading for Markdown ADR files.
A document has frontmatter when its first line is ---; the block ends
at the next line that is --- (or ...). YAML is loaded with a
yaml.SafeLoader variant that does not turn unquoted dates
into datetime.date objects: decision-date: 2024-13-01 would
otherwise make the whole block unparseable. Dates stay strings and are
validated by app.domain.records.
Public API:
- type app.domain.frontmatter.JsonValue = str | int | float | bool | None | list[JsonValue] | dict[str, JsonValue]¶
- class app.domain.frontmatter.FrontmatterSplit(yaml_text, body, unclosed=False)¶
Bases:
objectResult of splitting a document into frontmatter and body.
- Parameters:
- class app.domain.frontmatter.LoadedFrontmatter(fields, issue=None)¶
Bases:
objectResult of loading a frontmatter block.
- Parameters:
- app.domain.frontmatter.split_frontmatter(text)¶
Split canonical (LF-only) text into frontmatter and body.
- Parameters:
text (
str) – Canonical document text.- Return type:
- Returns:
The split result; never raises.
- app.domain.frontmatter.load_frontmatter(yaml_text)¶
Load a frontmatter block as a mapping of field names to values.
- Parameters:
yaml_text (
str) – The text between the delimiters.- Return type:
- Returns:
The loaded fields, or an empty mapping plus a
bad_yamlissue. Never raises for malformed content.
- app.domain.frontmatter.json_safe(value)¶
Convert a loaded YAML value into a JSON-serialisable value.
Mappings get string keys, sequences and sets become lists, dates use ISO format and any other unexpected scalar is rendered with
str.