Skip to content

fix(render): front matter only at the top of a file, never in a reply - #163

Merged
backnotprop merged 1 commit into
mainfrom
fix/mid-doc-front-matter
Nov 20, 2026
Merged

backnotprop merged 1 commit into
mainfrom
fix/mid-doc-front-matter

Conversation

@backnotprop

Copy link
Copy Markdown
Contributor

Cause

split_blocks (crates/plannotator-tui/src/doc.rs) parsed with ENABLE_YAML_STYLE_METADATA_BLOCKS and dropped every Metadata block. pulldown-cmark 0.13 does not require a metadata block to start the document: any unindented --- line followed by a non-blank line and a later --- counts. So a pair of rules in the middle of a reply hid everything between them.

Fix

  • Front matter is found once: the source must start with --- and pulldown-cmark must close a metadata block that begins at byte 0. The rest of the source is parsed with the option off, so every later --- is a thematic break or a setext underline. Block ranges still index the whole source, so anchors, block hints for top-of-file front matter, and exported line numbers do not move.
  • An agent's message (Provenance::AgentMessage) and piped text (Provenance::Stdin) get no front matter at all: a reply that opens with --- is content, as Claude Code and other previews show it. Files and Workspaces documents keep front matter. Open::new uses the new Document::of(&source); the other callers only open files and keep Document::parse.
  • Per-block parses (cjk_emphasis, decorate/syntax) keep parse_options() unchanged, so they still agree with tui-markdown, which renders each block on its own.

Tests

New unit tests in doc.rs: the reporter's document (failed before the fix), front matter at the top still dropped with a later rule pair kept and ranges unchanged, an unclosed --- at the top, a blank line after the top ---, --- as a setext underline, and a message vs. a file with the same text.

cargo fmt --check, cargo clippy --locked --workspace --all-targets -- -D warnings (1.96 and 1.99) and cargo test --locked --workspace pass.

In the binary (private tmux, scratch HOME and PLANNOTATOR_DATA_DIR): the reporter's file showed 3 blocks on main and all 8 with the fix; last --host claude --session <scratch transcript> with a reply that opens with --- showed only its last paragraph on main and the whole reply with the fix. A file with real front matter gives the same --blocks output before and after.

Fixes #162

pulldown-cmark takes a metadata block at any unindented `---` line that is
followed by text and a later `---`, not only at the start of the document.
split_blocks parsed with that option on and dropped every metadata block, so
a pair of rules in the middle of a document (common in agent replies) hid
everything between them.

Front matter is now found once, at byte 0, and the rest of the source is
parsed with the option off, so any later `---` is a rule or a setext
underline. Block ranges still index the whole source, so anchors and line
numbers are unchanged.

An agent's message or piped text has no front matter at all: a reply that
opens with `---` is content. Files and Workspaces documents keep it.

Fixes #162
@backnotprop
backnotprop added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit 9270322 Nov 20, 2026
3 checks passed
@backnotprop
backnotprop deleted the fix/mid-doc-front-matter branch November 20, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mid-document --- … --- is parsed as front matter and silently dropped (herdr last loses the middle of replies)

1 participant