UNPKG

@roadiehq/rag-ai

Version:

69 lines (66 loc) 2.24 kB
import React from 'react'; import ReactMarkdown from 'react-markdown'; import { Box } from '@material-ui/core'; import makeStyles from '@material-ui/core/styles/makeStyles'; import { CodeHighlighter } from '../CodeHighlighter.esm.js'; const useStyles = makeStyles((theme) => ({ markdown: { backgroundColor: theme.palette.background.default, color: theme.palette.text.primary }, code: { whiteSpace: "pre-wrap", padding: "2px 4px", borderRadius: "4px", backgroundColor: theme.palette.type === "light" ? "#f4f4f4" : "#2a2a2a", border: theme.palette.type === "light" ? "1px solid #ddd" : "1px solid #444", "&:not(pre > &)": { backgroundColor: theme.palette.type === "light" ? "#f4f4f4" : "#333333", border: theme.palette.type === "light" ? "1px solid #ddd" : "1px solid #444" } }, boxContainer: { padding: "1rem" }, link: { textDecoration: "revert-layer" } })); const LinkRenderer = ({ href, children }) => { const classes = useStyles(); return /* @__PURE__ */ React.createElement("a", { href, target: "_blank", rel: "noreferrer", className: classes.link }, children); }; const ResultRenderer = ({ result }) => { const classes = useStyles(); if (!result) { return null; } return /* @__PURE__ */ React.createElement(Box, { p: 3, className: `${classes.markdown} markdown-body` }, /* @__PURE__ */ React.createElement( ReactMarkdown, { children: result, components: { code(props) { const { children, className, node, ...rest } = props; const match = /language-(\w+)/.exec(className || ""); return match ? /* @__PURE__ */ React.createElement( CodeHighlighter, { text: String(children), language: match[1], showLineNumbers: false } ) : /* @__PURE__ */ React.createElement(Box, { p: 1, className: classes.code }, /* @__PURE__ */ React.createElement("code", { ...rest, className }, children)); }, a(props) { return /* @__PURE__ */ React.createElement(LinkRenderer, { ...props }); } } } )); }; export { ResultRenderer }; //# sourceMappingURL=ResultRenderer.esm.js.map