mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 23:49:03 +00:00
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { PropsWithChildren } from 'react'
|
|
import ReactMarkdown, { type Options } from 'react-markdown'
|
|
import remarkGfm from 'remark-gfm'
|
|
import { cn } from 'ui'
|
|
|
|
import { UntrackedInlineLink } from '@/components/ui/InlineLink'
|
|
|
|
interface MarkdownProps extends Omit<Options, 'children' | 'node'> {
|
|
className?: string
|
|
/** @deprecated Should remove this and just take `children` instead */
|
|
content?: string
|
|
extLinks?: boolean
|
|
}
|
|
|
|
const H3 = ({
|
|
children,
|
|
}: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>) => (
|
|
<h3 className="mb-1">{children}</h3>
|
|
)
|
|
const A = ({
|
|
href,
|
|
children,
|
|
}: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>) => (
|
|
// Markdown content can be user-written (cell values, row text), so a link's path must not reach telemetry
|
|
<UntrackedInlineLink href={href ?? '/'}>{children}</UntrackedInlineLink>
|
|
)
|
|
|
|
export const Markdown = ({
|
|
children,
|
|
className,
|
|
content = '',
|
|
extLinks = false,
|
|
...props
|
|
}: PropsWithChildren<MarkdownProps>) => {
|
|
return (
|
|
<div className={cn('text-sm', className)}>
|
|
<ReactMarkdown
|
|
remarkPlugins={[remarkGfm]}
|
|
components={{
|
|
h3: H3,
|
|
a: A,
|
|
}}
|
|
{...props}
|
|
>
|
|
{(children as string) ?? content}
|
|
</ReactMarkdown>
|
|
</div>
|
|
)
|
|
}
|