-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'katex/dist/katex.min.css' | ||
|
||
import {FC} from 'react' | ||
import ReactMarkdown from 'react-markdown' | ||
import rehypeKatex from 'rehype-katex' | ||
import remarkGfm from 'remark-gfm' | ||
import remarkMath from 'remark-math' | ||
|
||
import {Header, MarkdownLink, Ol, Paragraph, Ul} from './PostMarkdownTexts' | ||
|
||
type PostMarkdownProps = { | ||
content: string | ||
} | ||
|
||
export const PostMarkdown: FC<PostMarkdownProps> = ({content}) => ( | ||
<ReactMarkdown | ||
remarkPlugins={[remarkGfm, remarkMath]} | ||
rehypePlugins={[rehypeKatex]} | ||
components={{ | ||
a: MarkdownLink, | ||
p: Paragraph, | ||
h1: Header, | ||
h2: Header, | ||
h3: Header, | ||
h4: Header, | ||
h5: Header, | ||
h6: Header, | ||
ol: Ol, | ||
ul: Ul, | ||
}} | ||
disallowedElements={['table']} | ||
> | ||
{content} | ||
</ReactMarkdown> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {Typography} from '@mui/material' | ||
import {FC, ReactNode} from 'react' | ||
import {HeadingProps, OrderedListProps, ReactMarkdownProps, UnorderedListProps} from 'react-markdown/lib/ast-to-react' | ||
|
||
import {Link} from '../Clickable/Link' | ||
|
||
type MarkdownLinkProps = { | ||
children: ReactNode[] | ||
href?: string | ||
} | ||
|
||
export const MarkdownLink: FC<MarkdownLinkProps> = ({children, href}) => ( | ||
<Link href={href}> | ||
<Typography variant="postBody">{children}</Typography> | ||
</Link> | ||
) | ||
|
||
export const Ol: FC<OrderedListProps> = ({children}) => ( | ||
<Typography variant="postBody" component="ol"> | ||
{children} | ||
</Typography> | ||
) | ||
|
||
export const Ul: FC<UnorderedListProps> = ({children}) => ( | ||
<Typography variant="postBody" component="ul"> | ||
{children} | ||
</Typography> | ||
) | ||
|
||
export const Paragraph: FC<ReactMarkdownProps> = ({children}) => ( | ||
<Typography variant="postBody" mt={1} component="div"> | ||
{children} | ||
</Typography> | ||
) | ||
|
||
export const Header: FC<HeadingProps> = ({children}) => ( | ||
<Typography variant="postBody" mt={1} component="div" fontWeight={800}> | ||
{children} | ||
</Typography> | ||
) |