(
text: string,
cacheKey: string,
parser: { parse(text: string): string | Promise<string> },
)
| 53 | } |
| 54 | |
| 55 | export 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 | } |
no test coverage detected