* Extracts YAML frontmatter and Markdown body from a string. * Expects the format used by Claude Code SKILL.md, OpenCode agents, * and Cursor rules: `---` delimited YAML followed by Markdown content. * * @throws {Error} If the string does not contain valid `---` delimiters. * @returns The parse
(raw: string)
| 34 | * @returns The parsed frontmatter object and the body text. |
| 35 | */ |
| 36 | function parseMarkdownFrontmatter(raw: string): { |
| 37 | frontmatter: Record<string, unknown> |
| 38 | body: string |
| 39 | } { |
| 40 | const parts = raw.split(/^---$/m) |
| 41 | if (parts.length < 3) { |
| 42 | throw new Error('Invalid markdown frontmatter: missing --- delimiters') |
| 43 | } |
| 44 | return { |
| 45 | frontmatter: parseYaml(parts[1]) as Record<string, unknown>, |
| 46 | body: parts.slice(2).join('---').trim(), |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | function loadCustomModes(): CCBMode[] { |
| 51 | if (customModes !== null) return customModes |
no test coverage detected