The bodies of every fenced code block on the page, with the fence's indentation removed.
(text: string)
| 38 | |
| 39 | /** The bodies of every fenced code block on the page, with the fence's indentation removed. */ |
| 40 | function codeBlocks(text: string): string[] { |
| 41 | return [...text.matchAll(/^( *)```[^\n]*\n([\s\S]*?)^\1```$/gm)].map(([, indent, body]) => |
| 42 | body! |
| 43 | .split('\n') |
| 44 | .map((line) => (line.startsWith(indent!) ? line.slice(indent!.length) : line)) |
| 45 | .join('\n') |
| 46 | .trimEnd(), |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | function main(): number { |
| 51 | const blocks = new Map<string, string[]>(); |