(markdown: string)
| 84 | * tolerant of CommonMark closing hashes (`## Purpose ##`). |
| 85 | */ |
| 86 | export function extractFirstPurposeLine(markdown: string): string { |
| 87 | const lines = markdown.split(/\r?\n/); |
| 88 | let inPurpose = false; |
| 89 | let fenceMarker: string | null = null; |
| 90 | |
| 91 | for (const line of lines) { |
| 92 | // CommonMark: a fence closes only with its own marker kind. |
| 93 | const fence = line.match(/^\s*(```|~~~)/); |
| 94 | if (fence) { |
| 95 | if (fenceMarker === null) { |
| 96 | fenceMarker = fence[1]; |
| 97 | } else if (fence[1] === fenceMarker) { |
| 98 | fenceMarker = null; |
| 99 | } |
| 100 | continue; |
| 101 | } |
| 102 | if (fenceMarker !== null) { |
| 103 | continue; |
| 104 | } |
| 105 | |
| 106 | const heading = line.match(/^(#{1,6})\s+(.*)$/); |
| 107 | if (heading) { |
| 108 | if (inPurpose) { |
| 109 | return ''; |
| 110 | } |
| 111 | const title = heading[2].replace(/\s+#+\s*$/, '').trim(); |
| 112 | inPurpose = title.toLowerCase() === 'purpose'; |
| 113 | continue; |
| 114 | } |
| 115 | if (inPurpose && line.trim().length > 0) { |
| 116 | return line.trim(); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | return ''; |
| 121 | } |
| 122 | |
| 123 | async function collectSpecEntries(referencedRoot: string): Promise<ReferenceSpecEntry[]> { |
| 124 | const specIds = await getSpecIds(referencedRoot); |
no outgoing calls
no test coverage detected