mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 15:14:56 -04:00
markdown-it-configurator (#626)
Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Co-authored-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Co-authored-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
89968387c2
commit
0670cddb0b
42 changed files with 524 additions and 360 deletions
|
@ -1,12 +1,14 @@
|
|||
import MarkdownIt from 'markdown-it'
|
||||
import markdownItContainer from 'markdown-it-container'
|
||||
import Renderer from 'markdown-it/lib/renderer'
|
||||
import Token from 'markdown-it/lib/token'
|
||||
import { MarkdownItPlugin } from '../replace-components/ComponentReplacer'
|
||||
|
||||
type RenderContainerReturn = (tokens: Token[], index: number, options: MarkdownIt.Options, env: unknown, self: Renderer) => void;
|
||||
type ValidAlertLevels = ('warning' | 'danger' | 'success' | 'info')
|
||||
export const validAlertLevels: ValidAlertLevels[] = ['success', 'danger', 'info', 'warning']
|
||||
|
||||
export const createRenderContainer = (level: ValidAlertLevels): RenderContainerReturn => {
|
||||
const createRenderContainer = (level: ValidAlertLevels): RenderContainerReturn => {
|
||||
return (tokens: Token[], index: number, options: MarkdownIt.Options, env: unknown, self: Renderer) => {
|
||||
tokens[index].attrJoin('role', 'alert')
|
||||
tokens[index].attrJoin('class', 'alert')
|
||||
|
@ -14,3 +16,9 @@ export const createRenderContainer = (level: ValidAlertLevels): RenderContainerR
|
|||
return self.renderToken(tokens, index, options)
|
||||
}
|
||||
}
|
||||
|
||||
export const alertContainer: MarkdownItPlugin = (markdownIt: MarkdownIt) => {
|
||||
validAlertLevels.forEach(level => {
|
||||
markdownItContainer(markdownIt, level, { render: createRenderContainer(level) })
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue