@@ -303,9 +303,6 @@ def cell_output_to_nodes(outputs, data_priority, write_stderr, dir, thebe_config
303
303
continue
304
304
data = output ["data" ][mime_type ]
305
305
if mime_type .startswith ("image" ):
306
- ####################################
307
- # TODO: Figure out how to handle either inline or absolute image paths
308
-
309
306
# Sphinx treats absolute paths as being rooted at the source
310
307
# directory, so make a relative path, which Sphinx treats
311
308
# 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
361
358
362
359
def attach_outputs (output_nodes , node , thebe_config , cm_language ):
363
360
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" ]
365
363
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 )
368
366
output_node = CellOutputNode (classes = ["cell_output" ])
369
367
if thebe_config :
370
368
# Move the source from the input node into the thebe_source node
@@ -425,9 +423,8 @@ def apply(self):
425
423
thebe_config = self .config .jupyter_sphinx_thebelab_config
426
424
427
425
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
+
431
428
# Create doctree nodes for cell outputs.
432
429
output_nodes = cell_output_to_nodes (
433
430
output_bundle_node .outputs ,
@@ -449,17 +446,3 @@ def apply(self):
449
446
# is only available via event listeners.
450
447
col = ImageCollector ()
451
448
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