MCPcopy Create free account
hub / github.com/blacksmithgu/datacore / readCodeblock

Method readCodeblock

src/api/script-cache.ts:184–203  ·  view source on GitHub ↗

Read the contents of a codeblock from a file.

(file: TFile, block: MarkdownCodeblock)

Source from the content-addressed store, hash-verified

182
183 /** Read the contents of a codeblock from a file. */
184 private async readCodeblock(file: TFile, block: MarkdownCodeblock): Promise<Result<string, string>> {
185 try {
186 const raw = lineRange(
187 await this.store.vault.cachedRead(file),
188 block.$contentPosition.start,
189 block.$contentPosition.end
190 );
191
192 if (block.$style === "fenced") return Result.success(raw);
193 else
194 return Result.success(
195 raw
196 .split("\n")
197 .map((line) => line.trimStart())
198 .join("\n")
199 );
200 } catch (error) {
201 return Result.failure(`Failed to read a codeblock from ${file.path}: ${error}`);
202 }
203 }
204}

Callers 1

resolveSourceMethod · 0.95

Calls 3

lineRangeFunction · 0.90
joinMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected