(markdown, heading)
| 113 | } |
| 114 | |
| 115 | function extractSection(markdown, heading) { |
| 116 | const pattern = new RegExp(`^##\\s+${escapeRegExp(heading)}\\s*$`, "m"); |
| 117 | const match = markdown.match(pattern); |
| 118 | if (!match || match.index === undefined) return null; |
| 119 | |
| 120 | const start = match.index + match[0].length; |
| 121 | const nextHeading = markdown.slice(start).match(/\n##\s+/); |
| 122 | const end = nextHeading?.index === undefined ? markdown.length : start + nextHeading.index; |
| 123 | return markdown.slice(start, end); |
| 124 | } |
| 125 | |
| 126 | function escapeRegExp(value) { |
| 127 | return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); |
no test coverage detected