* Extract `@path` references from leaf text (not inside code spans/blocks). * A simple, conservative parser: skips fenced code blocks and inline code.
(content: string, baseDir: string)
| 47 | * A simple, conservative parser: skips fenced code blocks and inline code. |
| 48 | */ |
| 49 | function extractIncludes(content: string, baseDir: string): string[] { |
| 50 | const refs: string[] = [] |
| 51 | let inFence = false |
| 52 | for (const line of content.split(/\r?\n/)) { |
| 53 | if (/^```/.test(line.trim())) { |
| 54 | inFence = !inFence |
| 55 | continue |
| 56 | } |
| 57 | if (inFence) continue |
| 58 | // Strip inline code spans before scanning for @refs. |
| 59 | const stripped = line.replace(/`[^`]*`/g, "") |
| 60 | const regex = /(?:^|\s)@((?:\.\/|~\/|\/)?[^\s]+)/g |
| 61 | let match: RegExpExecArray | null |
| 62 | while ((match = regex.exec(stripped)) !== null) { |
| 63 | const ref = match[1].replace(/\\ /g, " ") |
| 64 | // Avoid matching emails, @mentions, etc. |
| 65 | if (!/^[A-Za-z0-9._~/-]/.test(ref)) continue |
| 66 | refs.push(resolveInclude(ref, baseDir)) |
| 67 | } |
| 68 | } |
| 69 | return refs |
| 70 | } |
| 71 | |
| 72 | /** Recursively load a memory file and all its @includes. */ |
| 73 | function loadWithIncludes( |
no test coverage detected