(content: string)
| 27 | } |
| 28 | |
| 29 | function extractDescription(content: string): string { |
| 30 | const fmEnd = content.indexOf('\n---', 4); |
| 31 | expect(fmEnd).toBeGreaterThan(0); |
| 32 | const frontmatter = content.slice(4, fmEnd); |
| 33 | const lines = frontmatter.split('\n'); |
| 34 | let description = ''; |
| 35 | let inDescription = false; |
| 36 | const descLines: string[] = []; |
| 37 | |
| 38 | for (const line of lines) { |
| 39 | if (line.match(/^description:\s*\|?\s*$/)) { |
| 40 | inDescription = true; |
| 41 | continue; |
| 42 | } |
| 43 | if (line.match(/^description:\s*\S/)) { |
| 44 | return line.replace(/^description:\s*/, '').trim(); |
| 45 | } |
| 46 | if (inDescription) { |
| 47 | if (line === '' || line.match(/^\s/)) { |
| 48 | descLines.push(line.replace(/^ /, '')); |
| 49 | } else { |
| 50 | break; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | if (descLines.length > 0) { |
| 56 | description = descLines.join('\n').trim(); |
| 57 | } |
| 58 | return description; |
| 59 | } |
| 60 | |
| 61 | function extractMarkdownSection(content: string, heading: string): string { |
| 62 | const escaped = heading.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); |
no test coverage detected