"use client"; import { Popover, PopoverTrigger, PopoverContent, } from "@/components/ui/popover"; import { useMemo } from "react"; import ReactMarkdown, { Components } from "react-markdown"; import rehypeRaw from "rehype-raw"; import { useTTS } from "./TTSProvider"; import rehypeHighlight from "@/lib/utils"; // Utility to escape regex special characters: function escapeRegExp(text: string) { return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); } export default function MarkdownRenderer({ rawContent, }: { rawContent: string; }) { // Obtain TTS info from context. // TTSProvider is already wrapping this component higher in the tree. const { currentSentence, sentences } = useTTS(); // Determine the text to highlight. const textToHighlight = useMemo(() => { if (!sentences || sentences.length === 0) return ""; return sentences[currentSentence] || ""; }, [sentences, currentSentence]); // Setup rehype plugins including our highlight plugin. const rehypePlugins = useMemo( () => [rehypeRaw, [rehypeHighlight, { textToHighlight }] as any], [textToHighlight] ); const components: Components = { h1: ({ node, ...props }) => (
), h2: ({ node, ...props }) => ( ), h3: ({ node, ...props }) => ( ), h4: ({ node, ...props }) => ( ), p: ({ node, ...props }) => ( ), img: ({ node, ...props }) => (
),
sup: ({ node, ...props }) => (
// TODO: get the references from the document and display them in a popover
Reference content goes here.