import type { PluginWithOptions } from 'markdown-it'; import { htmlBlockRule, HTMLBlockSequence } from './htmlBlockRule'; import { htmlInlineRule } from './htmlInlineRule'; export type CustomComponentPluginOptions = { /** * Custom HTML block sequences. A sequence is a pair of opening and closing HTML tags such as * `

` and `

`. This option can be used to add support for custom component sequences. * * @default [] */ customSequences?: HTMLBlockSequence[]; }; /** * Replacing the default `htmlBlock` rule to allow using custom components in markdown. */ export const customComponentPlugin: PluginWithOptions = (parser, { customSequences }: CustomComponentPluginOptions = {}): void => { // Override default html block ruler. parser.block.ruler.at('html_block', htmlBlockRule(customSequences), { alt: ['paragraph', 'reference', 'blockquote'], }); // Override default html inline ruler. parser.inline.ruler.at('html_inline', htmlInlineRule); };