Merge frontmatter/splitter: splitFrontmatter function with 18 tests

This commit is contained in:
2026-04-27 10:05:19 +00:00
4 changed files with 267 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
---
id: frontmatter/splitter
name: Implement frontmatter delimiter splitter (~40 lines)
status: pending
status: completed
depends_on:
- setup/project-init
scope: single
@@ -22,15 +22,15 @@ Per [frontmatter.md](../../../docs/architecture/frontmatter.md), the splitter:
## Acceptance Criteria
- [ ] `splitFrontmatter(markdown: string): { data: string; content: string } | null`
- [ ] Opening `---` must be at the start of the file (or after optional BOM/whitespace on first line)
- [ ] `----` (4+ dashes) is NOT a valid delimiter — only exact `---`
- [ ] Closing delimiter requires `\n---` (newline before dashes)
- [ ] Returns `null` if no valid frontmatter found
- [ ] Returns `{ data: "", content: "" }` if frontmatter is present but empty (e.g., `---\n---`)
- [ ] Content body starts after the closing `---` + newline
- [ ] Handles edge cases: no closing delimiter (returns null), file with only `---\n---`, file with no `---` at all
- [ ] Unit tests: standard frontmatter, no frontmatter, empty frontmatter, multi-line content, dashes in content body (shouldn't be treated as delimiters), 4+ dashes ignored
- [x] `splitFrontmatter(markdown: string): { data: string; content: string } | null`
- [x] Opening `---` must be at the start of the file (or after optional BOM/whitespace on first line)
- [x] `----` (4+ dashes) is NOT a valid delimiter — only exact `---`
- [x] Closing delimiter requires `\n---` (newline before dashes)
- [x] Returns `null` if no valid frontmatter found
- [x] Returns `{ data: "", content: "" }` if frontmatter is present but empty (e.g., `---\n---`)
- [x] Content body starts after the closing `---` + newline
- [x] Handles edge cases: no closing delimiter (returns null), file with only `---\n---`, file with no `---` at all
- [x] Unit tests: standard frontmatter, no frontmatter, empty frontmatter, multi-line content, dashes in content body (shouldn't be treated as delimiters), 4+ dashes ignored
## References
@@ -38,8 +38,13 @@ Per [frontmatter.md](../../../docs/architecture/frontmatter.md), the splitter:
## Notes
> To be filled by implementation agent
Self-contained `splitFrontmatter` function implemented with no external dependencies. Uses regex for opening delimiter match and manual scan for closing delimiter to enforce exact 3-dash rule. Handles BOM stripping and empty frontmatter.
## Summary
> To be filled on completion
Implemented the `splitFrontmatter` function in `src/frontmatter/parse.ts` per architecture spec.
- Modified: `src/frontmatter/parse.ts` (added `splitFrontmatter` function, ~65 lines including JSDoc)
- Modified: `src/frontmatter/index.ts` (exported `splitFrontmatter`)
- Modified: `test/frontmatter.test.ts` (18 comprehensive tests)
- Tests: 18 splitFrontmatter tests + 4 existing placeholder tests, all passing (22 total)
- TypeScript check: passing