{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "markdown-svelte",
  "title": "Markdown (Svelte)",
  "description": "Streaming markdown that parses only the blocks that changed.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/svelte@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup",
    "@kind-ui/code-block-svelte",
    "@kind-ui/markdown-table-svelte"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/svelte/markdown/Markdown.svelte",
      "content": "<!-- Renders `source` as it streams in, with code blocks and tables. -->\n<script lang=\"ts\">\n  import type { ComponentProps } from \"svelte\";\n  import MarkdownBlock from \"./MarkdownBlock.svelte\";\n  import { parts } from \"./parts\";\n\n  let props: ComponentProps<typeof parts.Root> & { children?: never } = $props();\n</script>\n\n<parts.Root {...props}>\n  {#snippet children({ blocks, highlight, streaming })}\n    <!-- Keyed by place, not `block.key`, which changes with the streaming tail's text, so the tail updates in place. -->\n    {#each blocks as block}\n      <MarkdownBlock {block} {highlight} streaming={streaming && !block.final} />\n    {/each}\n  {/snippet}\n</parts.Root>\n",
      "type": "registry:ui",
      "target": "@ui/svelte/markdown/Markdown.svelte"
    },
    {
      "path": "packages/agent-ui/src/svelte/markdown/MarkdownBlock.svelte",
      "content": "<!--\n  One parsed block. Nodes have no identity but their place in it, so they're drawn by index. A final block is the\n  same object on every append, so Svelte never draws it again.\n-->\n<script lang=\"ts\">\n  import type { Highlight, MarkdownBlock, MdNode } from \"@kind-ui/agent-ui/core\";\n  import { CodeBlock } from \"../code-block/index\";\n  import { MarkdownTable } from \"../markdown-table/index\";\n\n  type Row = { children: MdNode[] };\n  type Align = Extract<MdNode, { type: \"table\" }>[\"align\"];\n\n  let {\n    block,\n    highlight,\n    streaming,\n  }: { block: MarkdownBlock; highlight: Highlight | undefined; streaming: boolean } = $props();\n\n  const rows = (node: { children: MdNode[] }) => node.children as Row[];\n</script>\n\n{#snippet nodes(list: MdNode[], highlight: Highlight | undefined, streaming: boolean)}\n  {#each list as node}{@render one(node, highlight, streaming)}{/each}\n{/snippet}\n\n{#snippet row(cells: MdNode[], align: Align, head: boolean)}\n  <tr\n    >{#each cells as cell, index}{#if head}<th data-align={align[index] ?? undefined}\n          >{#if cell.type === \"tableCell\"}{@render nodes(cell.children, undefined, false)}{/if}</th\n        >{:else}<td data-align={align[index] ?? undefined}\n          >{#if cell.type === \"tableCell\"}{@render nodes(cell.children, undefined, false)}{/if}</td\n        >{/if}{/each}</tr\n  >\n{/snippet}\n\n{#snippet one(node: MdNode, highlight: Highlight | undefined, streaming: boolean)}\n  {#if node.type === \"text\"}{node.value}{:else if node.type === \"paragraph\"}<p\n      >{@render nodes(node.children, highlight, streaming)}</p\n    >{:else if node.type === \"heading\"}<svelte:element this={`h${node.depth}`}\n      >{@render nodes(node.children, highlight, streaming)}</svelte:element\n    >{:else if node.type === \"emphasis\"}<em>{@render nodes(node.children, highlight, streaming)}</em\n    >{:else if node.type === \"strong\"}<strong>{@render nodes(node.children, highlight, streaming)}</strong\n    >{:else if node.type === \"delete\"}<del>{@render nodes(node.children, highlight, streaming)}</del\n    >{:else if node.type === \"blockquote\"}<blockquote\n      >{@render nodes(node.children, highlight, streaming)}</blockquote\n    >{:else if node.type === \"inlineCode\"}<code>{node.value}</code>{:else if node.type === \"code\"}<CodeBlock\n      aria-label=\"Code\"\n      code={node.value}\n      language={node.lang}\n      {highlight}\n      {streaming}\n    />{:else if node.type === \"link\"}{#if node.url === null}<span\n        >{@render nodes(node.children, highlight, streaming)}</span\n      >{:else}<a href={node.url}>{@render nodes(node.children, highlight, streaming)}</a\n      >{/if}{:else if node.type === \"image\"}{#if node.url === null}<span>{node.alt}</span>{:else}<img\n        src={node.url}\n        alt={node.alt}\n      />{/if}{:else if node.type === \"list\"}{#if node.ordered}<ol start={node.start}\n        >{@render nodes(node.children, highlight, streaming)}</ol\n      >{:else}<ul>{@render nodes(node.children, highlight, streaming)}</ul>{/if}{:else if node.type === \"listItem\"}<li\n      data-task={node.checked === undefined ? undefined : \"\"}\n      >{#if node.checked !== undefined}<input\n          type=\"checkbox\"\n          checked={node.checked}\n          disabled\n          readonly\n        />{/if}{@render nodes(node.children, highlight, streaming)}</li\n    >{:else if node.type === \"table\"}{@const [head, ...body] = rows(node)}<MarkdownTable\n      aria-label=\"Table\"\n      style=\"--kind-markdown-table-columns: {node.align.length}\"\n      ><thead>{#if head}{@render row(head.children, node.align, true)}{/if}</thead><tbody\n        >{#each body as bodyRow}{@render row(bodyRow.children, node.align, false)}{/each}</tbody\n      ></MarkdownTable\n    >{:else if node.type === \"thematicBreak\"}<hr />{:else if node.type === \"break\"}<br />{/if}\n{/snippet}\n\n<div data-block-key={block.key}>{@render nodes((block.node as Row).children, highlight, streaming)}</div>\n",
      "type": "registry:ui",
      "target": "@ui/svelte/markdown/MarkdownBlock.svelte"
    },
    {
      "path": "packages/agent-ui/src/svelte/markdown/index.ts",
      "content": "import type { ComponentProps } from \"svelte\";\nimport Markdown from \"./Markdown.svelte\";\n\nexport { Markdown };\nexport type MarkdownProps = ComponentProps<typeof Markdown>;\n",
      "type": "registry:ui",
      "target": "@ui/svelte/markdown/index.ts"
    },
    {
      "path": "packages/agent-ui/src/svelte/markdown/parts.ts",
      "content": "import { markdownViewPrimitive } from \"@kind-ui/agent-ui/core\";\nimport { createParts } from \"@ui-sdk/svelte/primitive\";\n\nexport const parts = createParts(markdownViewPrimitive, { root: \"div\" });\n",
      "type": "registry:ui",
      "target": "@ui/svelte/markdown/parts.ts"
    }
  ],
  "meta": {
    "layer": "svelte"
  },
  "type": "registry:ui"
}
