Skip to content
Code & Tools

Parsing Markdown Front Matter in Python

Theo Marsh
1 min read
62
Last updated
Cover photo for “Parsing Markdown Front Matter in Python”

Our notes live in Markdown files with a little YAML on top. This script is how we turn them into something searchable.

Most of the improvement in a draft comes from cutting. We aim to remove a fifth of every piece on the second pass, and the reader never misses it.

front_matter.py
import yaml
from pathlib import Path

def read_note(path: Path) -> tuple[dict, str]:
    text = path.read_text(encoding="utf-8")
    if not text.startswith("---\n"):
        return {}, text
    _, meta, body = text.split("---\n", 2)
    return yaml.safe_load(meta) or {}, body.strip()

Deadlines help, but only when they are real. A deadline that everyone knows will slip is just a date on a calendar.

The first version of anything is a question, not an answer. Treating it that way makes feedback easier to give and much easier to hear.

Most of the improvement in a draft comes from cutting. We aim to remove a fifth of every piece on the second pass, and the reader never misses it.

1
Continue reading

Related posts

All posts
Conversation

Comments · 1

Posting as guest · Sign in
  1. Aiko Tanaka ·

    I watched the film again after reading this and noticed so many details I had missed.