modularize renderer (#552)

This commit is contained in:
mrdrogdrog 2020-09-08 21:49:42 +02:00 committed by GitHub
parent ac00bc98c0
commit a86d4cbc58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 580 additions and 455 deletions

View file

@ -1,7 +1,10 @@
import React from 'react'
import MarkdownIt from 'markdown-it'
import markdownItContainer from 'markdown-it-container'
import React, { useCallback } from 'react'
import { Table } from 'react-bootstrap'
import { Trans, useTranslation } from 'react-i18next'
import { MarkdownRenderer } from '../../../markdown-renderer/markdown-renderer'
import { BasicMarkdownRenderer } from '../../../markdown-renderer/basic-markdown-renderer'
import { createRenderContainer, validAlertLevels } from '../../../markdown-renderer/markdown-it-plugins/alert-container'
import { HighlightedCode } from '../../../markdown-renderer/replace-components/highlighted-fence/highlighted-code/highlighted-code'
import './cheatsheet.scss'
@ -27,6 +30,13 @@ export const Cheatsheet: React.FC = () => {
':smile:',
`:::info\n${t('editor.help.cheatsheet.exampleAlert')}\n:::`
]
const markdownItPlugins = useCallback((md: MarkdownIt) => {
validAlertLevels.forEach(level => {
md.use(markdownItContainer, level, { render: createRenderContainer(level) })
})
}, [])
return (
<Table className="table-condensed table-cheatsheet">
<thead>
@ -40,14 +50,10 @@ export const Cheatsheet: React.FC = () => {
return (
<tr key={key}>
<td>
<MarkdownRenderer
<BasicMarkdownRenderer
content={code}
wide={false}
onTaskCheckedChange={(_) => null}
onTocChange={() => false}
onMetaDataChange={() => false}
onFirstHeadingChange={() => false}
onLineMarkerPositionChanged={() => false}
onConfigureMarkdownIt={markdownItPlugins}
/>
</td>
<td className={'markdown-body'}>