(source: string, pattern: RegExp)
| 61 | } |
| 62 | |
| 63 | export function extractBlocks(source: string, pattern: RegExp): ExtractedBlock[] { |
| 64 | const blocks: ExtractedBlock[] = []; |
| 65 | let match: RegExpExecArray | null; |
| 66 | const p = new RegExp(pattern.source, pattern.flags); |
| 67 | while ((match = p.exec(source)) !== null) { |
| 68 | blocks.push({ |
| 69 | attrs: match[1] || "", |
| 70 | content: match[2] || "", |
| 71 | raw: match[0], |
| 72 | index: match.index, |
| 73 | }); |
| 74 | } |
| 75 | return blocks; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Find the `<html>` open tag in the source. Distinct from `findRootTag`, |