Bundle directives and roles into reusable plugins.
Plugin Structure
A plugin is a module that registers extensions:
# my_plugin/__init__.py
from patitas.plugins import Plugin
from patitas.directives import DirectiveRegistryBuilder
class MyPlugin(Plugin):
"""My custom plugin."""
name = "my-plugin"
def register_directives(self, builder: DirectiveRegistryBuilder) -> None:
"""Register custom directives."""
from .directives import MyDirective, AnotherDirective
builder.register(MyDirective())
builder.register(AnotherDirective())
Using Plugins
Enable plugins when creating a Markdown processor:
from patitas import Markdown
md = Markdown(plugins=["my-plugin"])
html = md(":::{my-directive}\nContent\n:::{/my-directive}")
Built-in Plugins
Patitas includes these plugins:
| Plugin | Description | Directives |
|---|---|---|
directives |
Core directives | admonition, container, dropdown, tabs |
math |
Math support | math, equation |
table |
Extended tables | table, csv-table |
Plugin Discovery
Plugins are discovered via entry points:
# pyproject.toml
[project.entry-points."patitas.plugins"]
my-plugin = "my_plugin:MyPlugin"
Plugin Dependencies
Declare dependencies:
class MyPlugin(Plugin):
name = "my-plugin"
dependencies = ["directives"] # Requires directives plugin
Plugin Configuration
Accept configuration options:
class MyPlugin(Plugin):
name = "my-plugin"
def __init__(self, *, option1: str = "default", **kwargs):
self.option1 = option1
# Usage
md = Markdown(plugins=[("my-plugin", {"option1": "custom"})])