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

View File

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