Python API¶
markdown_d2 exposes the two functions pymdownx.superfences needs for a
custom fence.
formatter ¶
formatter(*, root: str | Path = '.', cache_dir: str | Path | None = '.cache/markdown-d2', light_theme: int = 0, dark_theme: int = 200, dark_selector: str = '[data-md-color-scheme="slate"]', errors: Literal['raise', 'show'] = 'raise', timeout: float = 60, node: str | Path | None = None, transition: Literal['none', 'fade', 'morph'] = 'fade') -> Formatter
Return the function that turns a d2 block into a figure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str | Path
|
Folder that imports and icon paths are relative to. |
'.'
|
cache_dir
|
str | Path | None
|
Folder that keeps rendered SVGs between builds; |
'.cache/markdown-d2'
|
light_theme
|
int
|
D2 theme ID of the light picture; a diagram's own |
0
|
dark_theme
|
int
|
D2 theme ID of the dark picture; a diagram's own |
200
|
dark_selector
|
str
|
CSS selector of the page element that marks the dark theme. |
'[data-md-color-scheme="slate"]'
|
errors
|
Literal['raise', 'show']
|
|
'raise'
|
timeout
|
float
|
Seconds to wait for one diagram, every board in both themes. |
60
|
node
|
str | Path | None
|
Node program to run; by default the one |
None
|
transition
|
Literal['none', 'fade', 'morph']
|
How a diagram with several steps changes from one to the next:
|
'fade'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If transition is not one of those three. |
validator ¶
validator(language: str, inputs: dict[str, str], options: dict[str, Any], attrs: dict[str, Any], md: Markdown) -> bool
Accept every option of a d2 block; the formatter checks them.