API reference
API reference¶
Look up every public class and function of mkdeck.
You import everything on this page from the top-level mkdeck package. The one exception is the rollout converter, which lives in mkdeck.rollout. The public modules are mkdeck, mkdeck.errors, and mkdeck.rollout. Every other module is an implementation detail, and it can change between releases.
Deck.build and Deck.serve write and show a deck that you build in Python. load_source(...) returns a DeckSource with the same two methods for a deck written in Markdown. These are the only entry points. See Build a deck from Python for how they fit together.
The slide model¶
Markdown produces these classes, and the renderer reads them. You can also build them yourself.
mkdeck.Deck
dataclass
¶
A whole deck.
Attributes:
| Name | Type | Description |
|---|---|---|
title |
str
|
The deck title: the title of the page, and the text of the generated opening slide. |
date |
str | None
|
The deck date, shown on the opening slide and in the chrome. |
theme |
str
|
The name of the theme stylesheet to link. |
slides |
list[Slide]
|
The slides, in the order they are shown. |
units |
list[str]
|
The units the number highlighting recognises, in any order. |
extra_css |
list[str]
|
Extra stylesheets, linked after the theme. |
extra_js |
list[str]
|
Extra scripts, loaded after |
reveal |
dict[str, Any]
|
Options merged into |
title_slide |
bool
|
Whether to generate the opening title slide from |
Source code in src/mkdeck/model.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
build(out: Path | str = 'site', *, source: Path | str | None = None, single_file: bool = False) -> Path
¶
Write this deck to an output folder.
Building again into the same folder brings it up to date: every file is copied afresh, and a file the previous build wrote that this one no longer needs is removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out
|
Path | str
|
The output folder, or the HTML file when |
'site'
|
source
|
Path | str | None
|
The folder the deck's assets live in; the current directory when omitted. |
None
|
single_file
|
bool
|
True to inline every stylesheet and script. |
False
|
Returns:
| Type | Description |
|---|---|
Path
|
The path of the written HTML document. |
Raises:
| Type | Description |
|---|---|
DeckError
|
If the deck or a slide breaks a rule of the model, the
source folder does not exist, the output folder is the source
folder or its |
Source code in src/mkdeck/model.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
serve(*, source: Path | str | None = None, host: str = '127.0.0.1', port: int = 5020, open_browser: bool = False, reload: bool = True) -> None
¶
Serve this deck until interrupted.
The deck is the one in hand: it is built again, unchanged, whenever a
file under source changes. The Python code that made the slides is not
run again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Path | str | None
|
The folder the deck's assets live in; the current directory when omitted. It is watched, and the page reloads when a file in it changes. |
None
|
host
|
str
|
The interface to bind. |
'127.0.0.1'
|
port
|
int
|
The port to bind. |
5020
|
open_browser
|
bool
|
True to open the deck in a browser once it is up. |
False
|
reload
|
bool
|
True to watch |
True
|
Raises:
| Type | Description |
|---|---|
DeckError
|
If the deck cannot be rendered, the source folder does not exist, or the port is taken. |
Source code in src/mkdeck/model.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
mkdeck.Slide
dataclass
¶
One slide of a deck.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str | None
|
A stable identifier, emitted as |
layout |
Layout
|
How the slide is laid out; |
title |
str | None
|
The heading, drawn above the rest of the slide. A slide that holds nothing else is a title slide. |
sentence |
str | None
|
The visible headline. Inline Markdown and |
bullets |
list[str]
|
A compact list drawn under the sentence, with the same inline syntax. |
math |
list[str]
|
Display formulas, one per line, drawn above the sentence. |
embeds |
list[Embed]
|
The figures on the slide, at most |
table |
Table | None
|
The table on the slide, or |
html |
str | None
|
Raw HTML drawn with the rest of the slide. The escape hatch. |
notes |
str | None
|
Speaker notes, shown in reveal's presenter view. |
date |
str | None
|
On |
classes |
list[str]
|
Extra CSS classes put on the |
Source code in src/mkdeck/model.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
mkdeck.Embed
dataclass
¶
A figure on a slide: an iframe page, an image or an animation.
Attributes:
| Name | Type | Description |
|---|---|---|
src |
str
|
The page or image, relative to the deck source folder. An |
label |
str | None
|
The caption drawn above the frame, or |
kind |
EmbedKind
|
|
Source code in src/mkdeck/model.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
mkdeck.Table
dataclass
¶
A table on a slide.
Attributes:
| Name | Type | Description |
|---|---|---|
columns |
list[str]
|
The header cells, at least one. Each is shown with |
rows |
list[list[str]]
|
The body rows; every row holds one cell per column, each shown
with |
Source code in src/mkdeck/model.py
109 110 111 112 113 114 115 116 117 118 119 120 | |
mkdeck.DEFAULT_UNITS: tuple[str, ...] = ('N m s/rad', 'kg m^2', 'rad/s', 'body weights', 'N m', 'mm', 'ms', 'Hz', 'kg', 'm', 's', 'm/s', '%', 'percent', 'degrees')
module-attribute
¶
The units a number may carry and still be highlighted.
These apply when a deck does not set its own.
The order does not matter: the renderer tries the longest spelling first.
Load a deck from disk¶
mkdeck.load_source(path: Path | str) -> DeckSource
¶
Load a deck and its settings from disk.
The deck.yml beside the Markdown and the frontmatter are read once and
merged into the fields of the deck, the frontmatter winning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
A Markdown file, or a folder holding |
required |
Returns:
| Type | Description |
|---|---|
DeckSource
|
The loaded deck, with its source folder. |
Raises:
| Type | Description |
|---|---|
DeckError
|
If the path holds no deck, the file is not readable UTF-8 text, or the deck cannot be parsed. |
Source code in src/mkdeck/source.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
mkdeck.DeckSource
dataclass
¶
A deck loaded from disk, ready to build or serve.
Attributes:
| Name | Type | Description |
|---|---|---|
deck |
Deck
|
The parsed deck. The frontmatter and |
directory |
Path
|
The folder holding the Markdown and its assets. |
markdown |
Path
|
The Markdown file the deck came from. |
Source code in src/mkdeck/source.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
build(out: Path | str = 'site', *, single_file: bool = False) -> Path
¶
Write the deck to an output folder, with the assets it names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out
|
Path | str
|
The output folder, or the HTML file when |
'site'
|
single_file
|
bool
|
True to inline every stylesheet and script. |
False
|
Returns:
| Type | Description |
|---|---|
Path
|
The path of the written HTML document. |
Raises:
| Type | Description |
|---|---|
DeckError
|
If a slide breaks a rule of the model, the output folder is the deck folder, or a file the deck names is outside the deck folder. |
Source code in src/mkdeck/source.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
serve(*, host: str = '127.0.0.1', port: int = 5020, open_browser: bool = False, reload: bool = True) -> None
¶
Serve the deck until interrupted.
Read it again whenever its folder changes. While it is served from this machine, the text of a slide can be edited on the page, and the edit is written into the Markdown file.
The first build uses deck as it is, but every rebuild reads the
Markdown and deck.yml from disk again, so a change made to deck in
Python shows only until the first edit. To serve a deck that is changed
in Python, serve that Deck with Deck.serve instead.
The folder is watched apart from the ones mkdeck build, check and
export write into by default (site, report and deck.pdf).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
The interface to bind. |
'127.0.0.1'
|
port
|
int
|
The port to bind. |
5020
|
open_browser
|
bool
|
True to open the deck in a browser once it is up. |
False
|
reload
|
bool
|
True to watch the folder and push reloads. |
True
|
Raises:
| Type | Description |
|---|---|
DeckError
|
If the deck cannot be rendered or the port is taken. |
Source code in src/mkdeck/source.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
Errors and warnings¶
mkdeck.DeckError
¶
Bases: Exception
A deck could not be read, validated or rendered.
The string form of the error is <source>: <slide>: <message>, with the
parts that are known. Name the slide with mkdeck.model.slide_name so that
every message names it the same way.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
What went wrong and what the author should do about it. |
|
slide |
The offending slide, already named, or |
|
source |
The deck file or folder the problem came from, or |
Source code in src/mkdeck/errors.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
__init__(message: str, *, slide: str | None = None, source: Path | str | None = None) -> None
¶
Create the error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
What went wrong and what the author should do about it.
Write it as a complete sentence with its own subject, because it
is also shown without the prefix, for example |
required |
slide
|
str | None
|
The offending slide, named by |
None
|
source
|
Path | str | None
|
The deck file or folder the problem came from. |
None
|
Source code in src/mkdeck/errors.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
mkdeck.DeckWarning
¶
Bases: UserWarning
A problem that leaves the deck usable.
An embed that is not on disk is one such problem.
Source code in src/mkdeck/errors.py
56 57 58 59 60 | |
Rollouts¶
mkdeck rollout calls convert_brax_html. It reads one Brax playback page. It writes a .rollout file and, for a model it has not seen, a shared .meshes file. A page with no Brax scene raises NotBraxPage, which is a DeckError. A caller that converts a folder of pages can catch it and skip the page.
mkdeck.rollout.convert_brax_html(src: Path | str, out: Path | str) -> Converted
¶
Convert one Brax page into a rollout and its shared meshes.
The mesh file is named after its own content, so converting a second run of the same model writes only the small per-run file and leaves the meshes alone. Both files are written whole or not at all.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Path | str
|
The Brax |
required |
out
|
Path | str
|
The folder to write into; it is created when missing. |
required |
Returns:
| Type | Description |
|---|---|
Converted
|
Where the files went. |
Raises:
| Type | Description |
|---|---|
NotBraxPage
|
If the page holds no scene at all. |
DeckError
|
If the page holds a scene that cannot be converted. |
Source code in src/mkdeck/rollout.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | |
mkdeck.rollout.Converted
dataclass
¶
Where one conversion put its files.
Attributes:
| Name | Type | Description |
|---|---|---|
rollout |
Path
|
The written |
meshes |
Path
|
The shared |
shared |
bool
|
True when the mesh file was already there, written by an earlier run of the same model. |
Source code in src/mkdeck/rollout.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
mkdeck.rollout.NotBraxPage
¶
Bases: DeckError
The page is not a Brax playback page, which is not always a mistake.
An assets folder normally mixes playback pages with plots, so a caller converting a batch may want to skip these and still fail on the rest.
Source code in src/mkdeck/rollout.py
88 89 90 91 92 93 | |