Classes
MarimoCellDirective
Marimo cell directive for executable Python code blocks.
Syntax:
```{marimo}
import pandas…
MarimoCellDirective
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
DirectivePluginMethods 1
parse
Parse Marimo cell directive.
parse
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
Token dict with type and attributesdict[str, Any]
—
Internal Methods 5
__init__
Initialize Marimo directive.
__init__
def __init__(self) -> None
Initialize Marimo directive.
_check_marimo_available
Check if Marimo is installed.
_check_marimo_available
def _check_marimo_available(self) -> bool
Check if Marimo is installed.
Returns
bool
_execute_cell
Execute Python code using Marimo and return HTML output.
_execute_cell
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
HTML representation of cell executionstr
—
_render_error
Render user-friendly error message.
_render_error
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
HTML error displaystr
—
__call__
Register directive with Mistune.
__call__
def __call__(self, directive: Any, md: Any) -> Any
Register directive with Mistune.
Parameters 2
directive |
Any |
FencedDirective instance |
md |
Any |
Mistune Markdown instance |
Returns
Result of directive registrationAny
—
Functions
render_marimo_cell
Render Marimo cell HTML output.
render_marimo_cell
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
Wrapped HTML with cell containerstr
—