core/components/Markdown.tsx
dependabot[bot] 19293a0ec4
chore(deps): bump node-emoji and @types/node-emoji (#574)
* chore(deps): bump node-emoji and @types/node-emoji

Bumps [node-emoji](https://github.com/omnidan/node-emoji) and [@types/node-emoji](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node-emoji). These dependencies needed to be updated together.

Updates `node-emoji` from 1.10.0 to 2.1.0
- [Release notes](https://github.com/omnidan/node-emoji/releases)
- [Commits](https://github.com/omnidan/node-emoji/compare/v1.10.0...v2.1.0)

Updates `@types/node-emoji` from 1.8.1 to 2.1.0
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node-emoji)

---
updated-dependencies:
- dependency-name: node-emoji
  dependency-type: direct:production
  update-type: version-update:semver-major
- dependency-name: "@types/node-emoji"
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: remove @types/node-emoji

* fix: import

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: SKINMAKER <me@skinmaker.dev>
2023-06-20 21:18:32 +09:00

128 lines
2.3 KiB
TypeScript

import { FunctionComponent } from 'react'
import MarkdownView from 'react-showdown'
import sanitizeHtml from 'sanitize-html'
import * as Emoji from 'node-emoji'
import { anchorHeader, customEmoji, twemoji } from '@utils/Tools'
const Markdown: React.FC<MarkdownProps> = ({ text, options={}, allowedTag=[], components={} }) => {
return (
<div className='markdown-body w-full'>
<MarkdownView
markdown={Emoji.emojify(text)}
extensions={[twemoji, customEmoji, anchorHeader]}
options={{
openLinksInNewWindow: true,
underline: true,
omitExtraWLInCodeBlocks: true,
// literalMidWordUnderscores: true,
simplifiedAutoLink: true,
tables: true,
strikethrough: true,
smoothLivePreview: true,
tasklists: true,
ghCompatibleHeaderId: true,
encodeEmails: true,
...options
}}
components={components}
sanitizeHtml={html =>
sanitizeHtml(html, {
allowedTags: [
'addr',
'address',
'article',
'aside',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'section',
'blockquote',
'dd',
'div',
'dl',
'dt',
'hr',
'li',
'ol',
'p',
'pre',
'ul',
'a',
'abbr',
'b',
'bdi',
'bdo',
'br',
'cite',
'code',
'data',
'dfn',
'em',
'i',
'kbd',
'mark',
'q',
'rb',
'rp',
'rt',
'rtc',
'ruby',
's',
'samp',
'small',
'span',
'strong',
'sub',
'sup',
'time',
'u',
'var',
'wbr',
'caption',
'col',
'colgroup',
'table',
'tbody',
'td',
'tfoot',
'th',
'thead',
'tr',
'del',
'ins',
'img',
'svg',
'path',
'input',
...allowedTag
],
allowedAttributes: false,
allowedClasses: {
'*': ['align-middle'],
a: ['anchor', 'mr-1'],
svg: ['octicon-link'],
img: ['emoji', 'special']
},
allowedStyles: {}
})
}
/>
</div>
)
}
interface MarkdownProps {
text: string
options?: {
[key: string]: boolean
}
allowedTag?: string[]
components?: Record<string, FunctionComponent>
}
export default Markdown