import type { ComponentProps } from 'react' import { useRouter } from 'wouter' import ReactMarkdown, { defaultUrlTransform, type ExtraProps } from 'react-markdown' import rehypeHighlight from 'rehype-highlight' import remarkGfm from 'remark-gfm' import { useWorkspaceId } from '@/client/features/workspace/workspace-context' import { resolveUrl } from '@/lib/navigation' import { cn } from '@/client/lib/cn' const remarkPlugins = [remarkGfm] const rehypePlugins = [rehypeHighlight] const components = { code({ node: _node, className, children, ...props }: ComponentProps<'code'> & ExtraProps) { return ( {children} ) }, pre({ children }: ComponentProps<'pre'>) { return (
          {children}
        
) } } type MarkdownContentProps = { size?: 'sm' content: string } type PlainMarkdownTextProps = { content: string } export function MarkdownContent({ size = 'sm', content }: MarkdownContentProps) { const workspaceId = useWorkspaceId() const { base } = useRouter() return (
{ if (node.tagName === 'a' && key === 'href' && url.startsWith('moi:')) { try { return resolveUrl(url, { workspaceId, base }) } catch { return '' } } return defaultUrlTransform(url) }} > {content}
) } export function PlainMarkdownText({ content }: PlainMarkdownTextProps) { return ( {content} ) }