Module

rendering.plugins.directives.marimo

Marimo directive for Mistune.

Provides executable Python code blocks with output rendering using Marimo's reactive notebook system.

Classes

MarimoCellDirective
Marimo cell directive for executable Python code blocks. Syntax: ```{marimo} import pandas…
6

Marimo cell directive for executable Python code blocks.

Syntax:

```{marimo}
import pandas as pd
pd.DataFrame({"x": [1, 2, 3]})
```

Options:

:show-code: true/false - Display source code (default: true)
:cache: true/false - Cache execution results (default: true)
:label: str - Cell identifier for caching and cross-references

Features:

  • Execute Python code at build time
  • Render outputs (text, tables, plots, etc.)
  • Cache results for fast rebuilds
  • Show/hide source code
  • Graceful error handling
Inherits from DirectivePlugin

Methods 1

parse
Parse Marimo cell directive.
3 dict[str, Any]
def parse(self, block: Any, m: Any, state: Any) -> dict[str, Any]

Parse Marimo cell directive.

Parameters 3
block Any

Block parser

m Any

Regex match

state Any

Parser state

Returns

dict[str, Any]

Token dict with type and attributes

Internal Methods 5
__init__
Initialize Marimo directive.
0 None
def __init__(self) -> None

Initialize Marimo directive.

_check_marimo_available
Check if Marimo is installed.
0 bool
def _check_marimo_available(self) -> bool

Check if Marimo is installed.

Returns

bool

_execute_cell
Execute Python code using Marimo and return HTML output.
5 str
def _execute_cell(self, code: str, show_code: bool, page_id: str, use_cache: bool = True, label: str = '') -> str

Execute Python code using Marimo and return HTML output.

Parameters 5
code str

Python code to execute

show_code bool

Whether to display source code

page_id str

Page identifier for generator caching

use_cache bool

Whether to use cached results

label str

Optional label for the cell

Returns

str

HTML representation of cell execution

_render_error
Render user-friendly error message.
3 str
def _render_error(self, title: str, message: str, code: str) -> str

Render user-friendly error message.

Parameters 3
title str

Error title

message str

Error message

code str

Source code that caused the error

Returns

str

HTML error display

__call__
Register directive with Mistune.
2 Any
def __call__(self, directive: Any, md: Any) -> Any

Register directive with Mistune.

Parameters 2
directive Any

FencedDirective instance

md Any

Mistune Markdown instance

Returns

Any

Result of directive registration

Functions

render_marimo_cell
Render Marimo cell HTML output.
4 str
def render_marimo_cell(renderer: Any, html: str, cell_id: int, label: str = '') -> str

Render Marimo cell HTML output.

Parameters 4

Name Type Default Description
renderer Any

Mistune HTML renderer

html str

Cell HTML content

cell_id int

Numeric cell identifier

label str ''

Optional cell label

Returns

str

Wrapped HTML with cell container