"use client"; import { PortableText as SanityPortableText } from "@portabletext/react"; import Image from "next/image"; import { urlFor } from "@/lib/sanity"; import type { PortableTextBlock } from "@portabletext/types"; import { useState } from "react"; import ReactMarkdown from "react-markdown"; import type { Components } from "react-markdown"; import remarkGfm from "remark-gfm"; import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; import { oneLight } from "react-syntax-highlighter/dist/esm/styles/prism"; interface PortableTextProps { content: PortableTextBlock[]; } const codeTheme: any = oneLight; function CodeBlock({ code, language, filename, highlightedLines, }: { code: string; language?: string; filename?: string; highlightedLines: Set; }) { const [copied, setCopied] = useState(false); const displayLanguage = language || "text"; const handleCopy = async () => { try { await navigator.clipboard.writeText(code); setCopied(true); window.setTimeout(() => setCopied(false), 1200); } catch { setCopied(false); } }; return (
{(filename || language) && (
{filename || "Code"}
{displayLanguage}
)} highlightedLines.has(lineNumber) ? { style: { backgroundColor: "rgba(251, 191, 36, 0.2)", }, } : { style: {} } } wrapLines codeTagProps={{ style: { fontFamily: "inherit" } }} > {code}
); } const markdownComponents: Components = { h1: (props) => (

), h2: (props) => (

), h3: (props) => (

), p: (props) => (

), ul: (props) => (