What's wrong
The library treats consecutive frontmatter blocks as one header. PR #166 (fixing #138) made AddFrontmatter and CombineFrontmatter fold all of the blocks together, and ExtractBody, RemoveFrontmatter and ReplaceFrontmatter also treat every block as header. ExtractFrontmatter, however, still returns frontmatterObjects.First() (Frontmatter/Frontmatter.cs:139). As a result, properties in the second and later blocks appear in neither the extracted frontmatter nor the extracted body.
Repro
string doc = "---\ntitle: Hello\n---\n---\nauthor: Jane\n---\n# Body\n";
Frontmatter.ExtractFrontmatter(doc);
Frontmatter.ExtractBody(doc);
Frontmatter.RemoveFrontmatter(doc);
Frontmatter.AddFrontmatter(doc, new() { ["x"] = "1" });
Observed:
ExtractFrontmatter: { title: Hello } <- author missing
ExtractBody: # Body <- author block stripped as header
RemoveFrontmatter: # Body\n
AddFrontmatter(x=1): ---\ntitle: Hello\nauthor: Jane\nx: 1\n---\n# Body\n <- author IS part of the header here
Why it matters
A static-site or indexing tool that reads a page with ExtractFrontmatter plus ExtractBody loses author: Jane entirely: it is in neither the metadata nor the body. The same library's AddFrontmatter and CombineFrontmatter do count it as frontmatter, so the API gives different answers depending on which method is called.
Suggested fix / acceptance criteria
ExtractFrontmatter returns CombineAllFrontmatterObjects(ExtractFrontmatterObjects(input, out _)), the same first-block-wins fold that AddFrontmatter uses. It returns null when the result is empty.
- Test: for the document above,
ExtractFrontmatter returns both title and author.
- Test: when stacked blocks repeat a key, the first block's value wins, matching
AddFrontmatter_StackedBlocksRepeatAKey_FirstBlockWins.
What's wrong
The library treats consecutive frontmatter blocks as one header. PR #166 (fixing #138) made
AddFrontmatterandCombineFrontmatterfold all of the blocks together, andExtractBody,RemoveFrontmatterandReplaceFrontmatteralso treat every block as header.ExtractFrontmatter, however, still returnsfrontmatterObjects.First()(Frontmatter/Frontmatter.cs:139). As a result, properties in the second and later blocks appear in neither the extracted frontmatter nor the extracted body.Repro
Observed:
Why it matters
A static-site or indexing tool that reads a page with
ExtractFrontmatterplusExtractBodylosesauthor: Janeentirely: it is in neither the metadata nor the body. The same library'sAddFrontmatterandCombineFrontmatterdo count it as frontmatter, so the API gives different answers depending on which method is called.Suggested fix / acceptance criteria
ExtractFrontmatterreturnsCombineAllFrontmatterObjects(ExtractFrontmatterObjects(input, out _)), the same first-block-wins fold thatAddFrontmatteruses. It returns null when the result is empty.ExtractFrontmatterreturns bothtitleandauthor.AddFrontmatter_StackedBlocksRepeatAKey_FirstBlockWins.