# frontmatter

URL: /patitas/api/frontmatter/
Section: api
Description: YAML frontmatter parsing for Markdown and other content formats.

Provides parse_frontmatter and extract_body with graceful error handling.
parse_frontmatter returns (metadata, body); parse_notebook returns (content, metadata).

---

> For a complete page index, fetch /patitas/llms.txt.

Open LLM text
(/patitas/api/frontmatter/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Ffrontmatter%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Ffrontmatter%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Ffrontmatter%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Ffrontmatter%2Findex.txt)

Module

#
`frontmatter`

YAML frontmatter parsing for Markdown and other content formats.

Provides parse_frontmatter and extract_body with graceful error handling.
parse_frontmatter returns (metadata, body); parse_notebook returns (content, metadata).

4Functions

## Functions

`_find_delimiter_line`

1

`tuple[str, str] | None`

▼

Find closing --- delimiter on its own line. Returns (frontmatter_str, body) or …

`def _find_delimiter_line(content: str) -> tuple[str, str] | None`

Find closing --- delimiter on its own line. Returns (frontmatter_str, body) or None.

##### Parameters

Name
Type
Description

`content`
`str`

##### Returns

`tuple[str, str] | None`

`_normalize_metadata`

1

`dict[str, Any]`

▼

Coerce known numeric frontmatter fields to float.

Called immediately after yam…

`def _normalize_metadata(raw: dict[str, Any]) -> dict[str, Any]`

Coerce known numeric frontmatter fields to float.

Called immediately after yaml.safe_load() so every downstream consumer
(cascade, snapshots, sorts, templates) sees consistent types.

##### Parameters

Name
Type
Description

`raw`
`dict[str, Any]`

##### Returns

`dict[str, Any]`

`parse_frontmatter`

1

`tuple[dict[str, Any], st…`

▼

Parse YAML frontmatter from content. Returns (metadata, body).

Returns (metada…

`def parse_frontmatter(content: str) -> tuple[dict[str, Any], str]`

Parse YAML frontmatter from content. Returns (metadata, body).

Returns (metadata, body) — complementary to parse_notebook which returns
(markdown_content, metadata). Delimiters must be --- on their own line.

Behavior:

- Delimiters: --- at start, --- at end of block (line-boundary only)

- No leading ---: return ({}, content)

- Unclosed ---: return ({}, content) (treat as no frontmatter)

- Valid YAML: parse with yaml.safe_load, normalize numeric fields, return (metadata, body)

- YAML error: return ({}, body) where body = content with frontmatter block stripped

##### Parameters

Name
Type
Description

`content`
`str`

Raw file content with optional frontmatter

##### Returns

`tuple[dict[str, Any], str]`

`extract_body`

1

`str`

▼

Strip --- delimited block from start. No YAML parsing.

Uses line-boundary deli…

`def extract_body(content: str) -> str`

Strip --- delimited block from start. No YAML parsing.

Uses line-boundary delimiter detection (--- on its own line), so values
like title: "a---b" inside frontmatter do not truncate the body.

Use when parse_frontmatter fails (e.g. broken YAML) but you still want
the body content.

##### Parameters

Name
Type
Description

`content`
`str`

Full file content

##### Returns

`str`
