{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "markdown-math",
  "title": "Markdown Math",
  "description": "Math renderer for the markdown item, typeset with KaTeX. An expression that is still being written renders instead of throwing, and needs no math renderer registered, where the shell leaves the source literal.",
  "dependencies": [
    "cn",
    "katex@^0.19.1"
  ],
  "registryDependencies": [
    "litingyes/blocove/markdown-parse"
  ],
  "files": [
    {
      "path": "src/registry/blocove/ui/markdown/math.tsx",
      "content": "/* eslint-disable react/dom-no-dangerously-set-innerhtml -- the markup comes from KaTeX, which escapes its input and keeps its trust option off. */\n\nimport type { MarkdownMathProps } from '@/lib/blocove/markdown-parse'\nimport { cn } from 'cn'\nimport katex from 'katex'\nimport { useMemo } from 'react'\n\nexport interface MarkdownMathRendererProps extends MarkdownMathProps {\n  className?: string\n}\n\nfunction renderMath(value: string, display: boolean): string | null {\n  try {\n    // `throwOnError: false` renders the expression with KaTeX's own error color\n    // instead of throwing, which is what a half-written formula needs.\n    return katex.renderToString(value, {\n      displayMode: display,\n      throwOnError: false,\n      strict: 'ignore',\n    })\n  }\n  catch {\n    return null\n  }\n}\n\n/**\n * Math renderer for the markdown shell, powered by KaTeX.\n *\n * Register it through the shell's capability map:\n *\n * ```tsx\n * <Markdown source={source} components={{ math: MarkdownMath }} />\n * ```\n *\n * Consumers must import `katex/dist/katex.min.css` for the formula layout.\n * Without this renderer, the shell leaves `$…$` and `$$…$$` as text.\n */\nexport function MarkdownMath({\n  value,\n  display,\n  streaming,\n  className,\n}: MarkdownMathRendererProps) {\n  const html = useMemo(() => renderMath(value, display), [value, display])\n\n  if (html === null) {\n    return (\n      <code className={cn(className)} data-streaming={streaming || undefined}>\n        {display\n          ? `$$${value}$$`\n          : `$${value}$`}\n      </code>\n    )\n  }\n\n  if (display) {\n    return (\n      <div\n        className={cn('typeset-scroll', className)}\n        data-streaming={streaming || undefined}\n        dangerouslySetInnerHTML={{ __html: html }}\n      />\n    )\n  }\n\n  return (\n    <span\n      className={cn(className)}\n      data-streaming={streaming || undefined}\n      dangerouslySetInnerHTML={{ __html: html }}\n    />\n  )\n}\n",
      "type": "registry:ui",
      "target": "components/blocove/markdown/math.tsx"
    }
  ],
  "categories": [
    "markdown",
    "capability"
  ],
  "type": "registry:ui"
}