import { CodeBlock, Text } from "@prismicio/editor-ui"; import { ComponentProps, FC } from "react"; import ReactMarkdown from "react-markdown"; import type { CodeProps } from "react-markdown/lib/ast-to-react"; import remarkGfm from "remark-gfm"; import { telemetry } from "@/apiClient"; import { useAdapterName } from "@/hooks/useAdapterName"; import styles from "./MarkdownRenderer.module.css"; type MarkdownRenderer = FC<{ markdown: string; }>; type Language = ComponentProps["language"]; const MarkdownCodeBlock = (reactMarkdownProps: CodeProps) => { const { inline, ...props } = reactMarkdownProps; const adapter = useAdapterName(); if (inline === true) { return ; } const maybeFileInfo = (() => { if (props.node?.data?.meta !== undefined) { const meta = props.node?.data?.meta as string; const fileName = meta.substring(1, meta.length - 1); return { fileName, language: props.className?.split("-")[1], }; } return null; })(); const onCopy = () => { void telemetry.track({ event: "page-type:copy-snippet", framework: adapter, }); }; const classNameLanguage = /language-(\w+)/.exec(props.className ?? "")?.[1]; return ( ); }; export const MarkdownRenderer: MarkdownRenderer = ({ markdown }) => { return ( , h1: (props) => ( ), h2: (props) => ( ), h3: (props) => ( ), h4: (props) => ( ), h5: (props) => ( ), p: (props) => ( ), pre: (props) => ( ), }} /> ); };