// Renders the bundled docs (see markdown.ts) as React text nodes; nothing is parsed as HTML. // Links to the other bundled doc switch docs, `#anchors` scroll, and web links open in the // system browser. import type { ReactNode } from 'react'; import { anchorOf, inlineTokens, parseMarkdown, resolveLink, type DocLink } from './markdown.ts'; function inline(text: string, onLink: (link: DocLink) => void, docs: readonly string[]): ReactNode[] { return inlineTokens(text).map((token, index) => { if (token.kind === 'text') return token.text; if (token.kind === 'code') return {token.text}; if (token.kind === 'bold') return {token.text}; const link = resolveLink(token.href, docs); return link ? : {token.text}; }); } export function MarkdownDoc({ source, docs, onLink }: { source: string; docs: readonly string[]; onLink(link: DocLink): void }) { const blocks = parseMarkdown(source); return
{blocks.map((block, index) => { switch (block.kind) { case 'heading': { const Tag = `h${Math.min(block.level + 1, 5)}` as 'h2'; return {inline(block.text, onLink, docs)}; } case 'paragraph': return

{inline(block.text, onLink, docs)}

; case 'list': { const List = block.ordered ? 'ol' : 'ul'; return {block.items.map((item, n) =>
  • {inline(item, onLink, docs)}
  • )}
    ; } case 'table': return
    {block.head.map((cell, n) => )}{block.rows.map((row, r) => {row.map((cell, n) => )})}
    {inline(cell, onLink, docs)}
    {inline(cell, onLink, docs)}
    ; case 'code': return
    {block.text}
    ; } })}
    ; }