pr_01m47d24b0e6n91zwymwxg0vpx/apps/web/app/components/markdown.tsx
| 1 | import ReactMarkdown from "react-markdown"; |
| 2 | import { Link } from "react-router"; |
| 3 | import remarkGfm from "remark-gfm"; |
| 4 | |
| 5 | /** |
| 6 | * Renders markdown from repositories, briefs and docs. Raw HTML in the |
| 7 | * source is not rendered, so untrusted content is safe to pass in. |
| 8 | */ |
| 9 | export function Markdown({ source }: { source: string }) { |
| 10 | return ( |
| 11 | <div className="prose"> |
| 12 | <ReactMarkdown |
| 13 | remarkPlugins={[remarkGfm]} |
| 14 | components={{ |
| 15 | a({ href, children }) { |
| 16 | // In-site links navigate on the client. |
| 17 | return href?.startsWith("/") ? ( |
| 18 | <Link to={href}>{children}</Link> |
| 19 | ) : ( |
| 20 | <a href={href} rel="noreferrer nofollow"> |
| 21 | {children} |
| 22 | </a> |
| 23 | ); |
| 24 | }, |
| 25 | }} |
| 26 | > |
| 27 | {source} |
| 28 | </ReactMarkdown> |
| 29 | </div> |
| 30 | ); |
| 31 | } |