Plugins
Comark has two compatible extension layers. Comark plugins can transform source text, tokens, the parsed document, or rendered output through typed lifecycle hooks. You can also reuse parser plugins written for markdown-it through markdown-exit, Comark's markdown-it-compatible parser.
All built-in plugins ship in the core comark package. You install optional peer dependencies only for the plugins you use.
Default plugins
These plugins are enabled by default whenever you call parseMarkdown(), createMarkdownParser(), or a framework <Markdown> component. You don't need to install or register them.
plugins run afterward in the order you provide them. If an explicit plugin has the same name as a default plugin, it replaces that default and runs in its explicit position. If you provide the same explicit plugin name more than once, only the first instance runs.Disable default plugins
Turn them all off with registerDefaultPlugins: false:
import { parseMarkdown } from 'comark'
// Plain Markdown only, with no autolinks, components, attributes, HTML, alerts, or task lists
const result = await parseMarkdown(content, {
registerDefaultPlugins: false,
})Opt back into specific defaults via plugins:
import { parseMarkdown } from 'comark'
import components from 'comark/plugins/components'
import attributes from 'comark/plugins/attributes'
const result = await parseMarkdown(content, {
registerDefaultPlugins: false,
plugins: [components(), attributes()],
})See the registerDefaultPlugins and plugins options on the Parse API.
Plugins
Register optional plugins through the plugins option.
Guides
Use plugins
Pass plugins to parseMarkdown() or the <Markdown> component:
import { parseMarkdown } from 'comark'
import emoji from 'comark/plugins/emoji'
import toc from 'comark/plugins/toc'
const result = await parseMarkdown(content, {
plugins: [
emoji(),
toc({ depth: 3 })
]
})<script setup lang="ts">
import { Markdown } from '@comark/vue'
import emoji from '@comark/vue/plugins/emoji'
</script>
<template>
<Markdown :plugins="[emoji()]">{{ content }}</Markdown>
</template>import { Markdown } from '@comark/react'
import emoji from '@comark/react/plugins/emoji'
<Markdown plugins={[emoji()]}>{content}</Markdown><script>
import { Markdown } from '@comark/svelte'
import emoji from '@comark/svelte/plugins/emoji'
let content = '# Awesome'
</script>
<Markdown value={content} plugins={[emoji()]} />