Output Renderer¶
A Sphinx post-transform, to convert notebook outpus to AST nodes.
- class myst_nb.render_outputs.CellOutputsToNodes(document, startnode=None)[source]¶
Bases:
sphinx.transforms.post_transforms.SphinxPostTransform
Use the builder context to transform a CellOutputNode into Sphinx nodes.
- default_priority = 4¶
Numerical priority of this transform, 0 through 999 (override).
- exception myst_nb.render_outputs.MystNbEntryPointError[source]¶
Bases:
sphinx.errors.SphinxError
- category = 'MyST NB Renderer Load'¶
- myst_nb.render_outputs.load_renderer(name: str) myst_nb.render_outputs.CellOutputRendererBase [source]¶
Load a renderer, given a name within the
myst_nb.mime_render
entry point group
- class myst_nb.render_outputs.CellOutputRendererBase(document: docutils.nodes.document, node: myst_nb.nodes.CellOutputBundleNode, sphinx_dir: str)[source]¶
Bases:
abc.ABC
An abstract base class for rendering Notebook outputs to docutils nodes.
Subclasses should implement the
render
method.- __init__(document: docutils.nodes.document, node: myst_nb.nodes.CellOutputBundleNode, sphinx_dir: str)[source]¶
- Parameters
sphinx_dir – Sphinx “absolute path” to the output folder, so it is a relative path to the source folder prefixed with
/
.
- add_name(node: docutils.nodes.Node, name: str)[source]¶
Append name to node[‘names’].
Also normalize the name string and register it as explicit target.
- add_source_and_line(*nodes: List[docutils.nodes.Node])[source]¶
Add the source and line recursively to all nodes.
- cell_output_to_nodes(data_priority: List[str]) List[docutils.nodes.Node] [source]¶
Convert a jupyter cell with outputs and filenames to doctree nodes.
- Parameters
outputs – a list of outputs from a Jupyter cell
data_priority – media type by priority.
- Returns
list of docutils nodes
- make_error(error_msg: str) docutils.nodes.system_message [source]¶
Raise an exception or generate a warning if appropriate, and return a system_message node
- make_severe(error_msg: str) docutils.nodes.system_message [source]¶
Raise an exception or generate a warning if appropriate, and return a system_message node
- make_warning(error_msg: str) docutils.nodes.system_message [source]¶
Raise an exception or generate a warning if appropriate, and return a system_message node
- class myst_nb.render_outputs.CellOutputRenderer(document: docutils.nodes.document, node: myst_nb.nodes.CellOutputBundleNode, sphinx_dir: str)[source]¶
Bases:
myst_nb.render_outputs.CellOutputRendererBase
- render(mime_type: str, output: nbformat.notebooknode.NotebookNode, index: int) List[docutils.nodes.Node] [source]¶
Take a MIME bundle and MIME type, and return zero or more nodes.