import "server-only"; import { ExternalLinkIcon } from "lucide-react"; import ReactMarkdown, { defaultUrlTransform } from "react-markdown"; import rehypeRaw from "rehype-raw"; import rehypeSanitize, { defaultSchema } from "rehype-sanitize"; import remarkGfm from "remark-gfm"; import { Skeleton } from "@/components/ui/skeleton"; import { shortSha } from "@/lib/format"; import { fetchModelCard } from "@/lib/hub/client"; // Model cards mix Markdown and raw HTML. Parse the HTML (rehype-raw), then sanitize it: no scripts, // styles or event handlers, only the tags/attributes GitHub-style READMEs normally use. const schema = { ...defaultSchema, attributes: { ...defaultSchema.attributes, img: [...(defaultSchema.attributes?.img ?? []), "width", "height", "align", "loading"], div: [...(defaultSchema.attributes?.div ?? []), "align"], p: [...(defaultSchema.attributes?.p ?? []), "align"], td: [...(defaultSchema.attributes?.td ?? []), "align"], th: [...(defaultSchema.attributes?.th ?? []), "align"], }, }; /** * The Model card tab: the README at the pinned commit, fetched from the Hub (cached per commit). * Rendered inside a Suspense boundary, so the rest of the page doesn't wait for the Hub. */ export async function ModelCardSection({ repoId, sha }: { repoId: string; sha: string }) { const hub = `https://huggingface.co/${repoId}`; const card = await fetchModelCard(repoId, sha).catch(() => undefined); if (!card) { return (
{card === null ? "This repository has no model card." : "The model card could not be loaded."}{" "} Open on Hugging Face
); } return ( <>
This folder has no README.md. Add one to {localPath} and it shows up here after the
next scan of the models folder.
README.md in {localPath}, as of the last scan