Add GitHub-flavored Markdown support

This commit is contained in:
cte 2025-02-15 02:39:59 -08:00
parent 45bf2a0230
commit 347c69ebe6
4 changed files with 1019 additions and 31 deletions

File diff suppressed because it is too large Load diff

View file

@ -42,6 +42,7 @@
"react-use": "^17.5.1",
"react-virtuoso": "^4.7.13",
"rehype-highlight": "^7.0.0",
"remark-gfm": "^4.0.1",
"shell-quote": "^1.8.2",
"styled-components": "^6.1.13",
"tailwind-merge": "^2.6.0",

View file

@ -1,10 +1,10 @@
import { FC, memo } from "react"
import ReactMarkdown, { Options } from "react-markdown"
import remarkGfm from "remark-gfm"
import { Separator } from "@/components/ui"
import { CodeBlock } from "./CodeBlock"
import { SourceNumberButton } from "./SourceNumberButton"
import { Blockquote } from "./Blockquote"
const MemoizedReactMarkdown: FC<Options> = memo(
@ -25,6 +25,7 @@ export function Markdown({ content }: { content: string }) {
return (
<MemoizedReactMarkdown
remarkPlugins={[remarkGfm]}
className="custom-markdown break-words"
components={{
p({ children }) {
@ -77,23 +78,6 @@ export function Markdown({ content }: { content: string }) {
)
},
a({ href, children }) {
// If a text link starts with 'citation:', then render it as
// a citation reference.
if (
Array.isArray(children) &&
typeof children[0] === "string" &&
children[0].startsWith("citation:")
) {
const index = Number(children[0].replace("citation:", ""))
if (!isNaN(index)) {
return <SourceNumberButton index={index} />
}
// Citation is not looked up yet, don't render anything.
return null
}
return (
<a href={href} target="_blank" rel="noopener noreferrer">
{children}

View file

@ -1,13 +0,0 @@
import { cn } from "@/lib/utils"
export function SourceNumberButton({ index, className }: { index: number; className?: string }) {
return (
<span
className={cn(
"inline-flex h-5 w-5 items-center justify-center rounded-full bg-gray-100 text-xs",
className,
)}>
{index + 1}
</span>
)
}