Plugins
Plugin System
ndgBook supports a simple plugin system through Nim compiler extensions. Plugins can:
- Add custom RST directives for specialized content
- Modify the HTML output with custom templates
- Extend the search index with custom data
- Hook into the build pipeline for pre/post-processing
To create a plugin, write a Nim module that imports the compiler API and registers your extensions. Then compile it into the compiler or load it as a dynamic library.
# myplugin.nim import compiler/docgen, packages/docutils/rst proc initPlugin() = # Add custom directive rst.customDirectives["chart"] = proc(p: var RstParser): PRstNode = result = p.parseDirective(rnDirective, {hasArg}, parseSectionWrapper) initPlugin()
Note:
The plugin API is experimental and may change between versions. Pin your plugin to a specific Nim compiler version for stability.
Available Plugins
Community-maintained plugins include:
- ndgbook-mermaid: Renders Mermaid diagrams in documentation
- ndgbook-katex: Mathematical typesetting with KaTeX
- ndgbook-plantuml: PlantUML diagram support
- ndgbook-tabs: Tabbed content blocks
Install plugins through Nimble:
$ nimble install ndgbook-mermaid
Then enable them in your book's configuration:
doc.plugins = "mermaid katex"
Danger:
Plugins execute arbitrary Nim code during the build process. Only install plugins from trusted sources.