Skip to content

Commit 37be4df

Browse files
committed
addressing comments
1 parent b148a2a commit 37be4df

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

doc/source/index.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,11 @@ Styling options
336336
The CSS (Cascading Style Sheet) class structure of jupyter-sphinx is the
337337
following::
338338

339-
- jupyter_container
340-
- code_cell
341-
- stderr
342-
- output
339+
- jupyter_container, jupyter_cell
340+
- cell_input
341+
- cell_output
342+
- stderr
343+
- output
343344

344345
If a code cell is not displayed, the output is provided without the
345346
``jupyter_container``. If you want to adjust the styles, add a new stylesheet,

jupyter_sphinx/ast.py

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,6 @@ def cell_output_to_nodes(outputs, data_priority, write_stderr, dir, thebe_config
303303
continue
304304
data = output["data"][mime_type]
305305
if mime_type.startswith("image"):
306-
####################################
307-
# TODO: Figure out how to handle either inline or absolute image paths
308-
309306
# Sphinx treats absolute paths as being rooted at the source
310307
# directory, so make a relative path, which Sphinx treats
311308
# as being relative to the current working directory.
@@ -361,10 +358,11 @@ def cell_output_to_nodes(outputs, data_priority, write_stderr, dir, thebe_config
361358

362359
def attach_outputs(output_nodes, node, thebe_config, cm_language):
363360
if not node.attributes["hide_code"]: # only add css if code is displayed
364-
node.attributes["classes"] = ["jupyter_container"]
361+
classes = node.attributes.get("classes", [])
362+
classes += ["jupyter_container"]
365363

366-
input_node = _find_only_child_by_type(node, CellInputNode)
367-
outputbundle_node = _find_only_child_by_type(node, CellOutputBundleNode)
364+
(input_node,) = node.traverse(CellInputNode)
365+
(outputbundle_node,) = node.traverse(CellOutputBundleNode)
368366
output_node = CellOutputNode(classes=["cell_output"])
369367
if thebe_config:
370368
# Move the source from the input node into the thebe_source node
@@ -425,9 +423,8 @@ def apply(self):
425423
thebe_config = self.config.jupyter_sphinx_thebelab_config
426424

427425
for cell_node in self.document.traverse(JupyterCellNode):
428-
output_bundle_node = _find_only_child_by_type(
429-
cell_node, CellOutputBundleNode
430-
)
426+
(output_bundle_node,) = cell_node.traverse(CellOutputBundleNode)
427+
431428
# Create doctree nodes for cell outputs.
432429
output_nodes = cell_output_to_nodes(
433430
output_bundle_node.outputs,
@@ -449,17 +446,3 @@ def apply(self):
449446
# is only available via event listeners.
450447
col = ImageCollector()
451448
col.process_doc(self.app, node)
452-
453-
454-
def _find_only_child_by_type(node, node_type):
455-
found_nodes = list(node.traverse(node_type))
456-
if len(found_nodes) == 0:
457-
raise ValueError("Found no nodes of type %s in node %s" % (node_type, node))
458-
if len(found_nodes) > 1:
459-
raise ValueError(
460-
(
461-
"Found more than one nodes of type %s in node %s."
462-
"only return the first instance" % (node_type, node)
463-
)
464-
)
465-
return found_nodes[0]

0 commit comments

Comments
 (0)