1
0
mirror of synced 2025-12-21 19:06:49 -05:00
Files
docs/components/playground/ArticleMarkdown.tsx
Mike Surowiec 06d8f81401 Two-pane Experiment (#21092)
* pull changes from docs-playground

* cleanup, add callout banner

* cleanup linting and test fixes

* add discussion link

Co-authored-by: James M. Greene <JamesMGreene@github.com>
2021-08-26 14:19:40 -04:00

43 lines
1.2 KiB
TypeScript

import React from 'react'
import { useTheme } from '@primer/components'
import ReactMarkdown from 'react-markdown'
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
import { vs, vscDarkPlus } from 'react-syntax-highlighter/dist/cjs/styles/prism'
import gfm from 'remark-gfm'
type Props = {
className?: string
children: string
}
export const ArticleMarkdown = ({ className, children }: Props) => {
const theme = useTheme()
return (
<ReactMarkdown
className={className}
remarkPlugins={[gfm as any]}
components={{
// eslint-disable-next-line @typescript-eslint/no-unused-vars
code: ({ node, inline, className, children, ...props }) => {
const match = /language-(\w+)/.exec(className || '')
return !inline && match ? (
<SyntaxHighlighter
style={theme.colorScheme === 'dark' ? vscDarkPlus : vs}
language={match[1]}
PreTag="div"
children={String(children).replace(/\n$/, '')}
{...(props as any)}
/>
) : (
<code className={className} {...props}>
{children}
</code>
)
},
}}
>
{children}
</ReactMarkdown>
)
}