@@ -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
362359def 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