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

output_html

source

output_html(out: dict) -> 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
returns str Markdown for it: raw HTML, or Markdown when the output is Markdown

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