Skip to content

Close a frontmatter block at YAML's ... document end marker [patch] - #182

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/152-document-end-marker
Oct 6, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/152-document-end-marker

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #152

Problem

TrySplitFrontmatterBlocks only accepted --- as a closing delimiter. If a block was opened by --- and closed by Pandoc's ... document end marker, the block never closed. The scan carried on to the next --- in the document, which is usually a markdown horizontal rule. As a result:

  • RemoveFrontmatter and ReplaceFrontmatter deleted the body up to that rule.
  • ExtractBody returned only what came after the rule.
  • If there was no later ---, the document was treated as having no frontmatter at all.

Change

  • The close loop now also accepts a line whose TrimEnd() is ..., through a new IsClosingDelimiterLine.
  • ... never opens a block. Openers still go through IsDelimiterLine and HasFrontmatter.
  • An indented ... inside a block scalar does not close the block, because only a whole line equal to ... counts.
  • Rewritten documents always close their frontmatter with ---. The TrySplitFrontmatterBlocks remarks now say so.

Tests

DelimiterLineTests has seven new tests:

  • The issue's repro through ExtractFrontmatter, ExtractBody, RemoveFrontmatter and ReplaceFrontmatter.
  • ... with trailing whitespace and no later rule.
  • A lone ... on the first line is not an opener.
  • An indented ... inside a | value does not close the block.

With the fix reverted, the first five fail. The two guard tests pass either way, by design. The full suite passes: 237/237.

🤖 Generated with Claude Code

https://claude.ai/code/session_01N47Hdpq8iSMutiKdDS81pa


Generated by Claude Code

A block opened by `---` and closed by Pandoc's `...` was not closed, so the
scan ran on to the next `---` anywhere in the document (usually a markdown
horizontal rule). RemoveFrontmatter, ReplaceFrontmatter and ExtractBody then
deleted the body up to that rule, and with no later rule the block was not
recognised at all.

`...` now closes a block but never opens one, and an indented `...` inside a
value is left alone. Rewritten documents close their frontmatter with `---`.

Fixes #152

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N47Hdpq8iSMutiKdDS81pa
@sonarqubecloud

sonarqubecloud Bot commented Oct 5, 2026

Copy link
Copy Markdown

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.

Pandoc-style ... closing marker is not recognised, so the frontmatter runs on to a later --- rule and body text is deleted

1 participant