Module

plugins

Plugin system for Patitas Markdown parser.

Plugins extend Patitas with additional syntax support:

  • table: GFM-style pipe tables
  • strikethrough: deleted syntax
  • task_lists: - [ ] checkboxes (built into core, enabled by default)
  • footnotes: [^1] references
  • math: $inline$ and $$block$$ math
  • autolinks: Automatic URL and email detection

Usage:

>>> from patitas import Markdown
>>>
>>> # Enable specific plugins
>>> md = Markdown(plugins=["table", "strikethrough", "math"])
>>> html = md("| A | B |

|---|---| | 1 | 2 |") >>> >>> # Enable all plugins >>> md = Markdown(plugins=["all"])

Plugin Architecture:

Unlike mistune's regex-based plugins, Patitas uses a state-machine lexer.

Plugins hook into specific extension points:

  1. Inline plugins (strikethrough, math inline):

    • Registered with the inline parser
    • Called when special characters are encountered
  2. Block plugins (table, math block, footnote definitions):

    • Registered with the block scanner
    • Called at line start when block patterns match
  3. Post-processing plugins (footnotes, autolinks):

    • Transform AST or rendered output
    • Called after main parsing/rendering

    Thread Safety:

All plugins are stateless. State is stored in AST nodes or passed as arguments. Multiple threads can use the same plugin instances concurrently.

Classes

PatitasPlugin 4
Protocol for Patitas plugins. Plugins can hook into multiple extension points: - extend_lexer: Add…

Protocol for Patitas plugins.

Plugins can hook into multiple extension points:

  • extend_lexer: Add token types and scanning logic
  • extend_parser: Add parsing rules for new tokens
  • extend_renderer: Add rendering methods for new nodes

Thread Safety:

Plugins must be stateless. All state should be in AST nodes.

Methods

name 0 str
Plugin identifier.
property
def name(self) -> str
Returns
str
extend_lexer 1
Extend lexer with additional token scanning. Called once at parser configurati…
def extend_lexer(self, lexer_class: type[Lexer]) -> None

Extend lexer with additional token scanning.

Called once at parser configuration time. Should add methods or modify class behavior.

Parameters
Name Type Description
lexer_class
extend_parser 1
Extend parser with additional parsing rules. Called once at parser configurati…
def extend_parser(self, parser_class: type[Parser]) -> None

Extend parser with additional parsing rules.

Called once at parser configuration time. Should add methods or modify class behavior.

Parameters
Name Type Description
parser_class
extend_renderer 1
Extend renderer with additional render methods. Called once at parser configur…
def extend_renderer(self, renderer_class: type[HtmlRenderer]) -> None

Extend renderer with additional render methods.

Called once at parser configuration time. Should add methods for new node types.

Parameters
Name Type Description
renderer_class

Functions

register_plugin 1 type[PatitasPlugin]
Decorator to register a plugin. **Usage:** @register_plugin("table") class…
def register_plugin(name: str) -> type[PatitasPlugin]

Decorator to register a plugin.

Usage: @register_plugin("table") class TablePlugin: ...

Parameters
Name Type Description
name str

Plugin name for lookup

Returns
type[PatitasPlugin]
get_plugin 1 PatitasPlugin
Get a plugin instance by name.
def get_plugin(name: str) -> PatitasPlugin
Parameters
Name Type Description
name str

Plugin name (e.g., "table", "strikethrough")

Returns
PatitasPlugin
apply_plugins 4 None
Apply plugins to parser components.
def apply_plugins(plugins: list[str], lexer_class: type[Lexer], parser_class: type[Parser], renderer_class: type[HtmlRenderer]) -> None
Parameters
Name Type Description
plugins list[str]

List of plugin names to apply

lexer_class type[Lexer]

Lexer class to extend

parser_class type[Parser]

Parser class to extend

renderer_class type[HtmlRenderer]

Renderer class to extend