smalldocs.notebook

Turn a Jupyter notebook into Markdown that the page pipeline renders: its cells and their stored outputs, never run.

source

source

source(cell: dict) -> str

Join 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

source

fence_for(text: str) -> str

Choose 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

source

raw_html(content: str) -> str

Wrap 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

source

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

figure

source

figure(img: str, opts: dict, n: int) -> str

Put a picture in Quarto’s figure markup when the cell has fig-cap, fig-alt or fig-align.

Parameter Type Default Description
img str required The HTML of the picture
opts dict required The cell’s #| options
n int required Which figure of the cell this is, from 0, for a list of captions
returns str The picture, in a figure with its caption, when the cell asks for one

output_html

source

output_html(out: dict, opts: dict | None = None, n: int = 0) -> str

Render 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
opts dict | None None The cell’s #| options: fig-cap, fig-alt, fig-align, tbl-cap
n int 0 Which picture of the cell this is, from 0
returns str Markdown for it: raw HTML, or Markdown when the output is Markdown

code_attrs

source

code_attrs(own: dict) -> str

Pass a cell’s own code-fold, code-summary, code-line-numbers and code-overflow to its code block.

Parameter Type Default Description
own dict required The cell’s own #| options
returns str Attributes for the cell’s code block, empty when the cell sets none of them

wrap_outputs

source

wrap_outputs(outs: list[str], opts: dict) -> list[str]

Put a cell’s outputs in a column or a grid when its options ask for one; with none, the outputs are as they were.

Parameter Type Default Description
outs list[str] required The Markdown of a cell’s outputs
opts dict required The cell’s #| options: column, fig-column, tbl-column, layout-ncol and layout-nrow
returns list[str] The outputs, in a div when an option asks for one

to_markdown

source

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