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 1
Protocol for Patitas plugins. Plugins are lightweight markers that enable features in Patitas. The…

Protocol for Patitas plugins.

Plugins are lightweight markers that enable features in Patitas. The actual parsing behavior is controlled by ParseConfig via ContextVars.

To enable a plugin, pass its name to Markdown(plugins=[...]). The Markdown class reads the plugin names and sets the appropriate ParseConfig flags.

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

Functions

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. Note: This function is deprecated. Plugin …
def apply_plugins(plugins: list[str], lexer_class: type[Lexer], parser_class: type[Parser], renderer_class: type[HtmlRenderer]) -> None

Apply plugins to parser components.

Note: This function is deprecated. Plugin configuration is now handled by the Markdown class via ParseConfig and ContextVars. This function is kept for backward compatibility but no longer does anything.

Parameters
Name Type Description
plugins list[str]

List of plugin names to apply

lexer_class type[Lexer]

Lexer class to extend (unused)

parser_class type[Parser]

Parser class to extend (unused)

renderer_class type[HtmlRenderer]

Renderer class to extend (unused)