import { Box, Container, Link, List, ListItem, ListItemIcon, ListItemSecondaryAction, ListItemText, Typography, } from "@mui/material"; import Highlight from "react-highlight"; import LocalLibraryIcon from "@mui/icons-material/LocalLibrary"; import InputIcon from "@mui/icons-material/Input"; import { DocItem } from "../../types/nix"; import CodeIcon from "@mui/icons-material/Code"; import ReactMarkdown from "react-markdown"; // import hljs from "highlight.js"; // needed for nextjs to import the classes of github theme import "highlight.js/styles/github.css"; interface PreviewProps { docItem: DocItem; } export const Preview = (props: PreviewProps) => { const { docItem } = props; const { name, description, category, example, fn_type } = docItem; const getGeneratedExamples = () => { if (description) { // const regex = /\`\`\`.*\`\`\`/gm; const regex = /(```.+?```)/gms; console.log({ description, regex }); if (typeof description === "object") { return description .join(" ") .match(regex) ?.join("") ?.replace("```nix", "") ?.replace("```", ""); } else { return description .match(regex) ?.join("") ?.replace("```nix", "") ?.replace("```", ""); } } }; const finalExample = example || getGeneratedExamples(); console.log({ finalExample }); const prefix = category.split(/([\/.])/gm).at(4) || "builtins"; const libName = category .match(/(?:[a-zA-Z]*)\.nix/gm)?.[0] ?.replace(".nix", ""); const docsRef = `https://nixos.org/manual/nixpkgs/stable/#function-library-lib.${libName}.${name}`; return ( {`${prefix}.${name}`} {typeof description === "object" ? description.map((d, idx) => ( {d} )) : description && {description}} } /> {/* View Docs */} Example ) } secondary={ finalExample ? ( {finalExample} ) : ( {`no example yet provided`} ) } /> ); };