Plugins
Plugins can transform the parsed Semantic AST or the generated Render IR. Multiple plugins run in registration order.
Document transform
Section titled “Document transform”import type { MarkdownPlugin } from '@markvia/core'
const addDocumentBadge: MarkdownPlugin = { name: 'add-document-badge', transformDocument(document) { return { ...document, children: [ { id: 'badge', type: 'paragraph', position: document.position, children: [ { id: 'badge-text', type: 'text', position: document.position, value: 'Generated by a plugin', }, ], }, ...document.children, ], } },}IR transform
Section titled “IR transform”IR transforms are useful for consistently changing tags, attributes, or node structure:
const addClassName: MarkdownPlugin = { name: 'add-class-name', transformIR(ir) { return { ...ir, children: ir.children.map((node) => node.kind === 'element' ? { ...node, props: { ...node.props, class: 'markvia-content' } } : node, ), } },}
const runtime = createMarkdown({ plugins: [addClassName] })Plugins should preserve node positions and IDs so editors, incremental updates, and downstream renderers can continue to associate output with the original content.