Skip to content

Add parseFrontmatter(): expand the frontmatter mark body into structured semantic events #73

Description

@morisil

Motivation

The frontmatter mark's body is opaque text today (raw YAML/TOML). Consumers that want structured metadata — querying a key, transforming values, rendering metadata visibly — must parse the YAML themselves. Since the library's identity is semantic-event-stream tooling, frontmatter should optionally be expressible as events, queryable and transformable with the same machinery (transform DSL, matchers) instead of via a side-channel string.

Design sketch

An opt-in downstream operator (Flow<SemanticEvent>.parseFrontmatter() or similar), NOT parser behavior:

  • The raw text body stays the canonical representation inside the frontmatter mark. This preserves the round-trip fixpoint (comments, key order, |/> block scalars, quoting quirks survive verbatim) and the "parser never throws" guarantee (malformed YAML degrades gracefully as text). The operator replaces the body with structured events only for consumers that ask for it.
  • Vocabulary: dl/dt/dd for mappings, ul/li for sequences, nested recursively. This is the HTML-idiomatic encoding of a property tree, consistent with the parser's existing style of untagged marks carrying HTML names (p, em, table), and it means the existing HTML renderer displays frontmatter meaningfully with zero new rendering code.
  • Scalar type info (booleans, numbers, dates), if ever needed, can ride on an attribute (e.g. dd type="int"); plain text is fine for LLM-facing output.
  • Pragmatic YAML subset: scalars, flat and nested block mappings, block sequences, quoted strings. Anchors, aliases, flow syntax, and multi-line scalars fall back to emitting the unparsed text verbatim — a full multiplatform YAML parser in commonMain is out of scope.
  • The expansion is lossy by design (comments and formatting die), so it belongs strictly on the consuming side of pipelines, never on any path that later hits renderMarkdown() expecting a fixpoint.
  • TOML support can follow the same shape later; YAML first.

Context

Emerged from designing the frontmatter title operator (ensureFrontmatterTitle): title detection/injection is a line-level operation on the raw body, so the two features are decoupled — this issue tracks the structural parsing for when a real consumer materializes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions