@@ -400,6 +400,12 @@ def apply(self):
400
400
source = node .children [0 ]
401
401
source ["linenos" ] = True
402
402
403
+
404
+ # Add code cell CSS class
405
+ for node in nodes :
406
+ source = node .children [0 ]
407
+ source .attributes ["classes" ] = ["code_cell" ]
408
+
403
409
# Write certain cell outputs (e.g. images) to separate files, and
404
410
# modify the metadata of the associated cells in 'notebook' to
405
411
# include the path to the output file.
@@ -504,26 +510,23 @@ def cell_output_to_nodes(cell, data_priority, write_stderr, dir, thebe_config):
504
510
# Adds a "stderr" class that can be customized by the user for both
505
511
# the container and the literal_block.
506
512
#
507
- # Also adds "error" as a base class, which is a fairly common
508
- # class in Sphinx themes. It should result in differentiation
509
- # from stdout in most Sphinx themes.
510
- #
511
513
# Not setting "rawsource" disables Pygment hightlighting, which
512
514
# would otherwise add a <div class="highlight">.
513
515
514
- container = docutils .nodes .container (classes = ["error" , " stderr" ])
516
+ container = docutils .nodes .container (classes = ["stderr" ])
515
517
container .append (docutils .nodes .literal_block (
516
518
text = output ['text' ],
517
519
rawsource = '' , # disables Pygment highlighting
518
520
language = 'none' ,
519
- classes = ["error" , " stderr" ]
521
+ classes = ["stderr" ]
520
522
))
521
523
to_add .append (container )
522
524
else :
523
525
to_add .append (docutils .nodes .literal_block (
524
526
text = output ['text' ],
525
527
rawsource = output ['text' ],
526
528
language = 'none' ,
529
+ classes = ["output" , "stream" ]
527
530
))
528
531
elif (
529
532
output_type == 'error'
@@ -534,6 +537,7 @@ def cell_output_to_nodes(cell, data_priority, write_stderr, dir, thebe_config):
534
537
text = text ,
535
538
rawsource = text ,
536
539
language = 'ipythontb' ,
540
+ classes = ["output" , "traceback" ]
537
541
))
538
542
elif (
539
543
output_type in ('display_data' , 'execute_result' )
@@ -558,19 +562,23 @@ def cell_output_to_nodes(cell, data_priority, write_stderr, dir, thebe_config):
558
562
elif mime_type == 'text/html' :
559
563
to_add .append (docutils .nodes .raw (
560
564
text = data ,
561
- format = 'html'
565
+ format = 'html' ,
566
+ classes = ["output" , "text_html" ]
567
+
562
568
))
563
569
elif mime_type == 'text/latex' :
564
570
to_add .append (math_block (
565
571
text = data ,
566
572
nowrap = False ,
567
573
number = None ,
574
+ classes = ["output" , "text_latex" ]
568
575
))
569
576
elif mime_type == 'text/plain' :
570
577
to_add .append (docutils .nodes .literal_block (
571
578
text = data ,
572
579
rawsource = data ,
573
580
language = 'none' ,
581
+ classes = ["output" , "text_plain" ]
574
582
))
575
583
elif mime_type == 'application/javascript' :
576
584
to_add .append (docutils .nodes .raw (
@@ -587,13 +595,13 @@ def cell_output_to_nodes(cell, data_priority, write_stderr, dir, thebe_config):
587
595
def attach_outputs (output_nodes , node , thebe_config , cm_language ):
588
596
if thebe_config :
589
597
source = node .children [0 ]
590
-
591
598
thebe_source = ThebeSourceNode (hide_code = node .attributes ['hide_code' ],
592
599
code_below = node .attributes ['code_below' ],
593
600
language = cm_language )
594
601
thebe_source .children = [source ]
595
602
596
603
node .children = [thebe_source ]
604
+ node .attributes ["classes" ] = ["jupyter_container" ] # add jupyter classes even if thebe_config <-- CHECK
597
605
598
606
if not node .attributes ['hide_output' ]:
599
607
thebe_output = ThebeOutputNode ()
@@ -603,8 +611,11 @@ def attach_outputs(output_nodes, node, thebe_config, cm_language):
603
611
else :
604
612
node .children = node .children + [thebe_output ]
605
613
else :
614
+ # Only add container class if code is shown
606
615
if node .attributes ['hide_code' ]:
607
616
node .children = []
617
+ else :
618
+ node .attributes ["classes" ] = ["jupyter_container" ]
608
619
609
620
if not node .attributes ['hide_output' ]:
610
621
if node .attributes ['code_below' ]:
@@ -767,6 +778,12 @@ def build_finished(app, env):
767
778
768
779
def setup (app ):
769
780
# Configuration
781
+ # Copy stylesheet
782
+ src = os .path .join (os .path .dirname (__file__ ), 'css' )
783
+ dst = os .path .join (app .outdir , '_static' )
784
+ copy_asset (src , dst )
785
+ app .add_css_file ('jupyter-sphinx.css' )
786
+
770
787
app .add_config_value (
771
788
'jupyter_execute_kwargs' ,
772
789
dict (timeout = - 1 , allow_errors = True , store_widget_state = True ),
0 commit comments