MCPcopy Create free account
hub / github.com/Noumena-Network/code / applyMarkdown

Function applyMarkdown

src/utils/markdown.ts:424–462  ·  view source on GitHub ↗
(
  content: string,
  theme: ThemeName,
  highlight: CliHighlight | null = null,
)

Source from the content-addressed store, hash-verified

422}
423
424export function applyMarkdown(
425 content: string,
426 theme: ThemeName,
427 highlight: CliHighlight | null = null,
428): string {
429 const stripped = stripPromptXMLTags(content)
430 const shouldCache = stripped.length >= APPLY_MARKDOWN_CACHE_MIN_CONTENT_LENGTH
431 const cacheKey = shouldCache
432 ? `${hashContent(stripped)}|${theme}|${highlight ? 1 : 0}`
433 : undefined
434
435 if (cacheKey) {
436 const hit = applyMarkdownCache.get(cacheKey)
437 if (hit !== undefined) {
438 applyMarkdownCache.delete(cacheKey)
439 applyMarkdownCache.set(cacheKey, hit)
440 return hit
441 }
442 }
443
444 // String-only markdown preview paths (notably AskUserQuestion previews) do
445 // not go through Markdown.tsx, so they bypass the block/token caches above.
446 // Keep a tiny LRU here for large preview bodies to avoid repeatedly lexing
447 // and re-highlighting the same rendered file/markdown payload on rerender.
448 const rendered = lexMarkdownPreservingPreformattedDiagrams(stripped)
449 .map(_ => formatToken(_, theme, 0, null, null, highlight))
450 .join('')
451 .trim()
452
453 if (cacheKey) {
454 if (applyMarkdownCache.size >= APPLY_MARKDOWN_CACHE_MAX) {
455 const oldest = applyMarkdownCache.keys().next().value
456 if (oldest !== undefined) applyMarkdownCache.delete(oldest)
457 }
458 applyMarkdownCache.set(cacheKey, rendered)
459 }
460
461 return rendered
462}
463
464export function formatToken(
465 token: Token,

Callers 4

Markdown.test.tsFile · 0.85
PreviewBoxBodyFunction · 0.85

Calls 9

stripPromptXMLTagsFunction · 0.85
formatTokenFunction · 0.85
deleteMethod · 0.80
setMethod · 0.80
keysMethod · 0.80
hashContentFunction · 0.70
getMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected