(lines: string[])
| 23 | } |
| 24 | |
| 25 | export function extractNameAndDescription(lines: string[]): {name: string; description?: string} { |
| 26 | let name = ''; |
| 27 | let description: string | undefined = undefined; |
| 28 | |
| 29 | let i = 0; |
| 30 | for (; i < lines.length; i++) { |
| 31 | const line = lines[i]; |
| 32 | if (line.startsWith('# ')) { |
| 33 | name = line.replace(/^#\s+/, '').trim(); |
| 34 | i++; |
| 35 | break; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | let descLines: string[] = []; |
| 40 | let inCode = false; |
| 41 | for (; i < lines.length; i++) { |
| 42 | const line = lines[i]; |
| 43 | if (/^```/.test(line.trim())) { |
| 44 | inCode = !inCode; |
| 45 | } |
| 46 | if (inCode) { |
| 47 | continue; |
| 48 | } |
| 49 | if (line.trim() === '') { |
| 50 | if (descLines.length > 0) { |
| 51 | break; |
| 52 | } else { |
| 53 | continue; |
| 54 | } |
| 55 | } |
| 56 | if (/^#{1,6}\s/.test(line) || /^</.test(line.trim())) { |
| 57 | continue; |
| 58 | } |
| 59 | descLines.push(line); |
| 60 | } |
| 61 | if (descLines.length > 0) { |
| 62 | description = descLines.join('\n').trim(); |
| 63 | } |
| 64 | |
| 65 | return {name, description}; |
| 66 | } |
no test coverage detected