| 108 | } |
| 109 | |
| 110 | parseCodeBlock(): TaggedCodeBlock { |
| 111 | const language = this.readUntil('\n').trim(); |
| 112 | const codeLines: string[] = []; |
| 113 | while (!this.atEnd()) { |
| 114 | const lineStartPos = this.pos; |
| 115 | if (this.match('```')) { |
| 116 | // Check if it's the end of the code block |
| 117 | if (this.peek() === '\n') this.consume(); |
| 118 | break; |
| 119 | } else { |
| 120 | this.pos = lineStartPos; // Reset position if not matching '```' |
| 121 | } |
| 122 | const line = this.readUntil('\n'); |
| 123 | codeLines.push(line); |
| 124 | if (!this.atEnd()) this.consume(); // Consume the newline |
| 125 | } |
| 126 | const linesContent = codeLines.map((line) => ({ |
| 127 | content: [{ s: line }], |
| 128 | })); |
| 129 | return { |
| 130 | tag: 'code-block', |
| 131 | language, |
| 132 | lines: linesContent, |
| 133 | }; |
| 134 | } |
| 135 | |
| 136 | parseCallout(): TaggedCallout { |
| 137 | const typeMatch = this.readUntil('\n') |