( text: string )
| 36 | * Returns the line numbers and the YAML text between them, or null if not found. |
| 37 | */ |
| 38 | export function findFrontmatterBounds( |
| 39 | text: string |
| 40 | ): { startLine: number; endLine: number; yamlText: string } | null { |
| 41 | const lines = text.split("\n"); |
| 42 | |
| 43 | // Opening delimiter must be at the very first line |
| 44 | if (lines.length === 0 || lines[0].trim() !== "---") { |
| 45 | return null; |
| 46 | } |
| 47 | |
| 48 | // Find closing delimiter |
| 49 | for (let i = 1; i < lines.length; i++) { |
| 50 | if (lines[i].trim() === "---") { |
| 51 | const yamlLines = lines.slice(1, i); |
| 52 | return { |
| 53 | startLine: 0, |
| 54 | endLine: i, |
| 55 | yamlText: yamlLines.join("\n"), |
| 56 | }; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return null; // Unclosed frontmatter |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Parse frontmatter from a markdown document string. |
no outgoing calls