MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / parseCodeBlock

Method parseCodeBlock

src/common/markdown-block.ts:110–134  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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')

Callers 1

parseBlockMethod · 0.95

Calls 6

readUntilMethod · 0.95
consumeMethod · 0.80
matchMethod · 0.65
mapMethod · 0.65
atEndMethod · 0.45
peekMethod · 0.45

Tested by

no test coverage detected