( content: string, )
| 50 | * Returns an object with title and optional instructions, or null if not a magic doc |
| 51 | */ |
| 52 | export function detectMagicDocHeader( |
| 53 | content: string, |
| 54 | ): { title: string; instructions?: string } | null { |
| 55 | const match = content.match(MAGIC_DOC_HEADER_PATTERN) |
| 56 | if (!match || !match[1]) { |
| 57 | return null |
| 58 | } |
| 59 | |
| 60 | const title = match[1].trim() |
| 61 | |
| 62 | // Look for italics on the next line after the header (allow one optional blank line) |
| 63 | const headerEndIndex = match.index! + match[0].length |
| 64 | const afterHeader = content.slice(headerEndIndex) |
| 65 | // Match: newline, optional blank line, then content line |
| 66 | const nextLineMatch = afterHeader.match(/^\s*\n(?:\s*\n)?(.+?)(?:\n|$)/) |
| 67 | |
| 68 | if (nextLineMatch && nextLineMatch[1]) { |
| 69 | const nextLine = nextLineMatch[1] |
| 70 | const italicsMatch = nextLine.match(ITALICS_PATTERN) |
| 71 | if (italicsMatch && italicsMatch[1]) { |
| 72 | const instructions = italicsMatch[1].trim() |
| 73 | return { |
| 74 | title, |
| 75 | instructions, |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return { title } |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Register a file as a Magic Doc when it's read |
no outgoing calls
no test coverage detected