mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-21 18:55:19 -04:00
Add markdown renderer for motd (#1840)
* Add markdown renderer for motd Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
21c12fafba
commit
57cb6f5b15
15 changed files with 102 additions and 55 deletions
|
@ -21,12 +21,14 @@ import { SanitizerMarkdownExtension } from '../markdown-extension/sanitizer/sani
|
|||
* @param markdownContentLines The markdown code lines that should be rendered
|
||||
* @param additionalMarkdownExtensions A list of {@link MarkdownExtension markdown extensions} that should be used
|
||||
* @param newlinesAreBreaks Defines if the alternative break mode of markdown it should be used
|
||||
* @param allowHtml Defines if html is allowed in markdown
|
||||
* @return The React DOM that represents the rendered markdown code
|
||||
*/
|
||||
export const useConvertMarkdownToReactDom = (
|
||||
markdownContentLines: string[],
|
||||
additionalMarkdownExtensions: MarkdownExtension[],
|
||||
newlinesAreBreaks?: boolean
|
||||
newlinesAreBreaks = true,
|
||||
allowHtml = true
|
||||
): ValidReactDomElement[] => {
|
||||
const lineNumberMapper = useMemo(() => new LineIdMapper(), [])
|
||||
const htmlToReactTransformer = useMemo(() => new NodeToReactTransformer(), [])
|
||||
|
@ -40,8 +42,8 @@ export const useConvertMarkdownToReactDom = (
|
|||
|
||||
const markdownIt = useMemo(() => {
|
||||
const newMarkdownIt = new MarkdownIt('default', {
|
||||
html: true,
|
||||
breaks: newlinesAreBreaks ?? true,
|
||||
html: allowHtml,
|
||||
breaks: newlinesAreBreaks,
|
||||
langPrefix: '',
|
||||
typographer: true
|
||||
})
|
||||
|
@ -52,7 +54,7 @@ export const useConvertMarkdownToReactDom = (
|
|||
newMarkdownIt.use((markdownIt) => extension.configureMarkdownItPost(markdownIt))
|
||||
)
|
||||
return newMarkdownIt
|
||||
}, [markdownExtensions, newlinesAreBreaks])
|
||||
}, [allowHtml, markdownExtensions, newlinesAreBreaks])
|
||||
|
||||
useMemo(() => {
|
||||
const replacers = markdownExtensions.reduce(
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
import type { Element, Node } from 'domhandler'
|
||||
import { isText } from 'domhandler'
|
||||
import type MarkdownIt from 'markdown-it'
|
||||
import type { ReactElement } from 'react'
|
||||
|
||||
export type ValidReactDomElement = ReactElement | string | null
|
||||
|
@ -15,8 +14,6 @@ export type SubNodeTransform = (node: Node, subKey: number | string) => NodeRepl
|
|||
|
||||
export type NativeRenderer = () => ValidReactDomElement
|
||||
|
||||
export type MarkdownItPlugin = MarkdownIt.PluginSimple | MarkdownIt.PluginWithOptions | MarkdownIt.PluginWithParams
|
||||
|
||||
export const REPLACE_WITH_NOTHING = null
|
||||
export const DO_NOT_REPLACE = undefined
|
||||
export type NodeReplacement = ValidReactDomElement | typeof REPLACE_WITH_NOTHING | typeof DO_NOT_REPLACE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue