chore: added Message component

This commit is contained in:
wonderlandpark 2021-03-07 21:38:56 +09:00
parent ad612cde0f
commit cde1b1f11e
2 changed files with 10 additions and 3 deletions

View File

@ -1,9 +1,11 @@
import { anchorHeader, customEmoji, twemoji } from '@utils/Tools'
import MarkdownView from 'react-showdown'
import sanitizeHtml from 'sanitize-html'
import Emoji from 'node-emoji'
import { FunctionComponent } from 'react'
const Markdown = ({ text, options={} }: MarkdownProps): JSX.Element => {
import { anchorHeader, customEmoji, twemoji } from '@utils/Tools'
const Markdown = ({ text, options={}, allowedTag=[], components={} }: MarkdownProps): JSX.Element => {
return (
<div className='markdown-body w-full'>
<MarkdownView
@ -23,6 +25,7 @@ const Markdown = ({ text, options={} }: MarkdownProps): JSX.Element => {
encodeEmails: true,
...options
}}
components={components}
sanitizeHtml={html =>
sanitizeHtml(html, {
allowedTags: [
@ -94,6 +97,7 @@ const Markdown = ({ text, options={} }: MarkdownProps): JSX.Element => {
'svg',
'path',
'input',
...allowedTag
],
allowedAttributes: false,
})
@ -108,6 +112,8 @@ interface MarkdownProps {
options?: {
[key: string]: boolean
}
allowedTag?: string[]
components?: Record<string, FunctionComponent>
}
export default Markdown

View File

@ -8,6 +8,7 @@ import { join } from 'path'
import { DocsData } from '@types'
import NotFound from 'pages/404'
import Message from '@components/Message'
const DeveloperLayout = dynamic(() => import('@components/DeveloperLayout'))
const Markdown = dynamic(() => import ('@components/Markdown'))
@ -30,7 +31,7 @@ const Docs: NextPage<DocsProps> = ({ docs }) => {
<div className='px-2'>
{
!document ? ''
: <Markdown text={document.text} options={{ openLinksInNewWindow: false }}/>
: <Markdown text={document.text} options={{ openLinksInNewWindow: false }} components={{ message: Message }} allowedTag={['message']} />
}
</div>
</DeveloperLayout>