Skip to content

Commit

Permalink
👌 IMPROVE: Use configured nb_render_plugin for glue nodes (#337)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Sewell <chrisj_sewell@hotmail.com>
  • Loading branch information
bryanwweber and chrisjsewell authored Jan 3, 2022
1 parent 2baade0 commit 9ade331
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions myst_nb/nb_glue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@


def glue(name, variable, display=True):
"""Glue an variable into the notebook's cell metadata.
"""Glue a variable into the notebook's cell metadata.
Parameters
----------
name: string
A unique name for the variable. You can use this name to refer to the variable
later on.
variable: python object
variable: Python object
A variable in Python for which you'd like to store its display value. This is
not quite the same as storing the object itself - the stored information is
what is *displayed* when you print or show the object in a Jupyter Notebook.
Expand Down
10 changes: 5 additions & 5 deletions myst_nb/nb_glue/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def copy(self):
return obj

def create_node(self, output: dict, document, env):
"""Create the output node, give the cell output."""
"""Create the output node, given the cell output."""
# the whole output chunk is deposited and rendered later
# TODO move these nodes to separate module, to avoid cyclic imports
output_node = CellOutputBundleNode([output], "default")
output_node = CellOutputBundleNode([output], env.config["nb_render_plugin"])
out_node = CellOutputNode(classes=["cell_output"])
out_node.source, out_node.line = self.source, self.line
out_node += output_node
Expand All @@ -50,7 +50,7 @@ def create_node(self, output: dict, document, env):

class PasteInlineNode(PasteNode):
def create_node(self, output: dict, document, env):
"""Create the output node, give the cell output."""
"""Create the output node, given the cell output."""
# the whole output chunk is deposited and rendered later
bundle_node = CellOutputBundleNode([output], "inline")
inline_node = nodes.inline("", "", bundle_node, classes=["pasted-inline"])
Expand All @@ -66,7 +66,7 @@ def formatting(self):
return self.attributes["formatting"]

def create_node(self, output: dict, document, env):
"""Create the output node, give the cell output."""
"""Create the output node, given the cell output."""
mimebundle = output["data"]
if "text/plain" in mimebundle:
text = mimebundle["text/plain"].strip("'")
Expand All @@ -90,7 +90,7 @@ class PasteMathNode(PasteNode):
"""

def create_node(self, output: dict, document, env):
"""Create the output node, give the cell output."""
"""Create the output node, given the cell output."""
mimebundle = output["data"]
if "text/latex" in mimebundle:
text = mimebundle["text/latex"].strip("$")
Expand Down
8 changes: 4 additions & 4 deletions myst_nb/nb_glue/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@


def read_glue_cache(path):
"""Read a glue cache generated by Sphinx build.
"""Read a glue cache generated by a Sphinx build.
Parameters
----------
path : str
Path to a doctree dir, or directly to a glue cache .json file.
Path to a doctree directory, or directly to a glue cache .json file.
Returns
-------
Expand Down Expand Up @@ -64,10 +64,10 @@ def find_glued_key(path_ntbk, key):
bundle = {this_key: val for key, val in bundle.items()}
outputs.append(bundle)
if len(outputs) == 0:
raise KeyError(f"Did not find key {this_key} in notebook {path_ntbk}")
raise KeyError(f"Did not find key {key} in notebook {path_ntbk}")
if len(outputs) > 1:
raise KeyError(
f"Multiple variables found for key: {this_key}. Returning first value."
f"Multiple variables found for key: {key}. Returning first value."
)
return outputs[0]

Expand Down
2 changes: 1 addition & 1 deletion myst_nb/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def metadata(self) -> NotebookNode:

@property
def renderer(self) -> str:
"""The cell level metadata for this output."""
"""The renderer for this output cell."""
return self._renderer

def copy(self):
Expand Down

0 comments on commit 9ade331

Please sign in to comment.