smalldocs.notebook
Turn a Jupyter notebook into Markdown that the page pipeline renders: its cells and their stored outputs, never run.
source
source(cell: dict) -> strJoin a cell’s source, which a notebook may store as a list of lines.
| Parameter | Type | Default | Description |
|---|---|---|---|
cell |
dict | required | A notebook cell |
| returns | str | Its source as one string |
fence_for
fence_for(text: str) -> strChoose a code fence that the text cannot close.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | What goes inside the fence |
| returns | str | A run of backticks longer than any in the text |
raw_html
raw_html(content: str) -> strWrap HTML in a raw {=html} block.
| Parameter | Type | Default | Description |
|---|---|---|---|
content |
str | required | HTML |
| returns | str | A Markdown raw block that passes the HTML through untouched |
cell_options
cell_options(code: str) -> tuple[dict, str]Read Quarto’s #| key: value options from the top of a code cell.
| Parameter | Type | Default | Description |
|---|---|---|---|
code |
str | required | The source of a code cell |
| returns | tuple[dict, str] | The #| options, and the code without them |
output_html
output_html(out: dict) -> strRender one stored output as Quarto does: streams and plain text in <pre>, pictures inline, HTML as it is.
| Parameter | Type | Default | Description |
|---|---|---|---|
out |
dict | required | One output of a code cell |
| returns | str | Markdown for it: raw HTML, or Markdown when the output is Markdown |
to_markdown
to_markdown(text: str, defaults: dict | None = None) -> tuple[dict, str]Turn a notebook into front matter and Markdown, as Quarto renders a notebook without running it.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | The notebook’s JSON |
defaults |
dict | None | None |
The page’s echo, output and include, which a cell’s #| options override |
| returns | tuple[dict, str] | Its front matter, and its body as Markdown |