(raw: string)
| 235 | * body (e.g. a markdown horizontal rule) never confuses the close fence. Returns |
| 236 | * null when there is no leading frontmatter block. */ |
| 237 | export function splitFrontmatter(raw: string): { frontmatter: string; body: string } | null { |
| 238 | const text = raw.replace(/^\uFEFF/, '') |
| 239 | const lines = text.split(/\r?\n/) |
| 240 | if (lines[0]?.trim() !== '---') return null |
| 241 | let end = -1 |
| 242 | for (let i = 1; i < lines.length; i++) { |
| 243 | if (lines[i].trim() === '---') { |
| 244 | end = i |
| 245 | break |
| 246 | } |
| 247 | } |
| 248 | if (end === -1) return null |
| 249 | return { |
| 250 | frontmatter: lines.slice(1, end).join('\n'), |
| 251 | body: lines.slice(end + 1).join('\n').trim(), |
| 252 | } |
| 253 | } |
no outgoing calls
no test coverage detected