import React from "react"; import ReactMarkdown from "react-markdown"; import rehypeRaw from "rehype-raw"; import rehypeSanitize from "rehype-sanitize"; import remarkGfm from "remark-gfm"; import { cn } from "@/lib/utils"; import { Citation } from "./chat/Citation"; import { Source } from "./chat/types"; interface MarkdownViewerProps { content: string; className?: string; getCitationSource?: (id: number) => Source | null; } export function MarkdownViewer({ content, className, getCitationSource }: MarkdownViewerProps) { return (
{ // If there's no getCitationSource function, just render normally if (!getCitationSource) { return

{children}

; } // Process citations within paragraph content return

{processCitationsInReactChildren(children, getCitationSource)}

; }, a: ({node, children, ...props}) => { // Process citations within link content if needed const processedChildren = getCitationSource ? processCitationsInReactChildren(children, getCitationSource) : children; return {processedChildren}; }, ul: ({node, ...props}) =>