MCPcopy Create free account
hub / github.com/anomalyco/opencode / preloadMarkdown

Function preloadMarkdown

packages/session-ui/src/components/markdown-cache.tsx:55–78  ·  view source on GitHub ↗
(
  text: string,
  cacheKey: string,
  parser: { parse(text: string): string | Promise<string> },
)

Source from the content-addressed store, hash-verified

53}
54
55export async function preloadMarkdown(
56 text: string,
57 cacheKey: string,
58 parser: { parse(text: string): string | Promise<string> },
59) {
60 await Promise.all(
61 project(undefined, text, false).blocks.map(async (block, index) => {
62 if (block.mode === "code") return
63 const key = `${cacheKey}:${index}:${block.mode}`
64 const cached = getCachedMarkdown(key)
65 if (cached?.raw === block.raw) {
66 touchCachedMarkdown(key, cached)
67 return
68 }
69 const hash = checksum(block.raw)
70 if (!hash) return
71 touchCachedMarkdown(key, {
72 raw: block.raw,
73 hash,
74 html: sanitizeMarkdown(await Promise.resolve(parser.parse(block.src))),
75 })
76 }),
77 )
78}

Callers 2

NewHomeFunction · 0.90

Calls 6

projectFunction · 0.90
checksumFunction · 0.90
getCachedMarkdownFunction · 0.85
touchCachedMarkdownFunction · 0.85
sanitizeMarkdownFunction · 0.85
allMethod · 0.45

Tested by

no test coverage detected