mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-21 10:45:20 -04:00
Move toolbar functions into redux reducer (#1763)
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
a6a2251c88
commit
b30cc5b390
80 changed files with 2481 additions and 2303 deletions
|
@ -18,7 +18,7 @@ import { SanitizerMarkdownExtension } from '../markdown-extension/sanitizer/sani
|
|||
/**
|
||||
* Renders markdown code into react elements
|
||||
*
|
||||
* @param markdownCode The markdown code that should be rendered
|
||||
* @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
|
||||
* @return The React DOM that represents the rendered markdown code
|
||||
|
@ -77,7 +77,6 @@ export const useConvertMarkdownToReactDom = (
|
|||
|
||||
return useMemo(() => {
|
||||
const html = markdownIt.render(markdownContentLines.join('\n'))
|
||||
|
||||
htmlToReactTransformer.resetReplacers()
|
||||
|
||||
return convertHtmlToReact(html, {
|
||||
|
|
|
@ -7,12 +7,13 @@
|
|||
import { MarkdownExtension } from './markdown-extension'
|
||||
import type MarkdownIt from 'markdown-it'
|
||||
import { Logger } from '../../../utils/logger'
|
||||
import { isDevMode } from '../../../utils/test-modes'
|
||||
|
||||
const log = new Logger('DebuggerMarkdownExtension')
|
||||
|
||||
export class DebuggerMarkdownExtension extends MarkdownExtension {
|
||||
public configureMarkdownItPost(markdownIt: MarkdownIt): void {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (isDevMode()) {
|
||||
markdownIt.core.ruler.push('printStateToConsole', (state) => {
|
||||
log.debug('Current state', state)
|
||||
return false
|
||||
|
|
|
@ -13,22 +13,25 @@ import { escapeHtml } from 'markdown-it/lib/common/utils'
|
|||
export class SpoilerMarkdownExtension extends MarkdownExtension {
|
||||
private static readonly spoilerRegEx = /^spoiler\s+(.*)$/
|
||||
|
||||
private static createSpoilerContainer(tokens: Token[], index: number): string {
|
||||
/**
|
||||
* Renders the opening and closing token of the container.
|
||||
*
|
||||
* @param tokens The tokens of the document
|
||||
* @param index The currently viewed token
|
||||
* @return The html rendering of the tokens
|
||||
*/
|
||||
private static renderSpoilerContainer(tokens: Token[], index: number): string {
|
||||
const matches = SpoilerMarkdownExtension.spoilerRegEx.exec(tokens[index].info.trim())
|
||||
|
||||
if (tokens[index].nesting === 1 && matches && matches[1]) {
|
||||
// opening tag
|
||||
return `<details><summary>${escapeHtml(matches[1])}</summary>`
|
||||
} else {
|
||||
// closing tag
|
||||
return '</details>\n'
|
||||
}
|
||||
return tokens[index].nesting === 1 && matches && matches[1]
|
||||
? `<details><summary>${escapeHtml(matches[1])}</summary>`
|
||||
: '</details>\n'
|
||||
}
|
||||
|
||||
public configureMarkdownIt(markdownIt: MarkdownIt): void {
|
||||
markdownItContainer(markdownIt, 'spoiler', {
|
||||
validate: (params: string) => SpoilerMarkdownExtension.spoilerRegEx.test(params),
|
||||
render: SpoilerMarkdownExtension.createSpoilerContainer.bind(this)
|
||||
render: SpoilerMarkdownExtension.renderSpoilerContainer.bind(this)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue