@@ -746,43 +746,17 @@ def setup(app):
746
746
747
747
app .add_config_value ('jupyter_sphinx_thebelab_url' , THEBELAB_URL_DEFAULT , 'html' )
748
748
749
- # JupyterKernelNode is just a doctree marker for the
750
- # ExecuteJupyterCells transform, so we don't actually render it.
749
+ # Used for nodes that do not need to be rendered
751
750
def skip (self , node ):
752
751
raise docutils .nodes .SkipNode
753
752
754
- app .add_node (
755
- JupyterKernelNode ,
756
- html = (skip , None ),
757
- latex = (skip , None ),
758
- textinfo = (skip , None ),
759
- text = (skip , None ),
760
- man = (skip , None ),
761
- )
762
-
763
-
764
- # JupyterCellNode is a container that holds the input and
765
- # any output, so we render it as a container.
753
+ # Renders the children of a container
766
754
render_container = (
767
755
lambda self , node : self .visit_container (node ),
768
756
lambda self , node : self .depart_container (node ),
769
757
)
770
758
771
- app .add_node (
772
- JupyterCellNode ,
773
- html = render_container ,
774
- latex = render_container ,
775
- textinfo = render_container ,
776
- text = render_container ,
777
- man = render_container ,
778
- )
779
-
780
- # JupyterWidgetViewNode holds widget view JSON,
781
- # but is only rendered properly in HTML documents.
782
- def visit_widget_html (self , node ):
783
- self .body .append (node .html ())
784
- raise docutils .nodes .SkipNode
785
-
759
+ # Used to render the container and its children as HTML
786
760
def visit_container_html (self , node ):
787
761
self .body .append (node .visit_html ())
788
762
self .visit_container (node )
@@ -791,6 +765,12 @@ def depart_container_html(self, node):
791
765
self .depart_container (node )
792
766
self .body .append (node .depart_html ())
793
767
768
+ # Used to render an element node as HTML
769
+ def visit_element_html (self , node ):
770
+ self .body .append (node .html ())
771
+ raise docutils .nodes .SkipNode
772
+
773
+ # Used to render the ThebeSourceNode conditionally for non-HTML builders
794
774
def visit_thebe_source (self , node ):
795
775
if node ['hide_code' ]:
796
776
raise docutils .nodes .SkipNode
@@ -802,9 +782,34 @@ def visit_thebe_source(self, node):
802
782
lambda self , node : self .depart_container (node )
803
783
)
804
784
785
+
786
+ # JupyterKernelNode is just a doctree marker for the
787
+ # ExecuteJupyterCells transform, so we don't actually render it.
788
+ app .add_node (
789
+ JupyterKernelNode ,
790
+ html = (skip , None ),
791
+ latex = (skip , None ),
792
+ textinfo = (skip , None ),
793
+ text = (skip , None ),
794
+ man = (skip , None ),
795
+ )
796
+
797
+ # JupyterCellNode is a container that holds the input and
798
+ # any output, so we render it as a container.
799
+ app .add_node (
800
+ JupyterCellNode ,
801
+ html = render_container ,
802
+ latex = render_container ,
803
+ textinfo = render_container ,
804
+ text = render_container ,
805
+ man = render_container ,
806
+ )
807
+
808
+ # JupyterWidgetViewNode holds widget view JSON,
809
+ # but is only rendered properly in HTML documents.
805
810
app .add_node (
806
811
JupyterWidgetViewNode ,
807
- html = (visit_widget_html , None ),
812
+ html = (visit_element_html , None ),
808
813
latex = (skip , None ),
809
814
textinfo = (skip , None ),
810
815
text = (skip , None ),
@@ -814,22 +819,27 @@ def visit_thebe_source(self, node):
814
819
# but is only rendered in HTML documents.
815
820
app .add_node (
816
821
JupyterWidgetStateNode ,
817
- html = (visit_widget_html , None ),
822
+ html = (visit_element_html , None ),
818
823
latex = (skip , None ),
819
824
textinfo = (skip , None ),
820
825
text = (skip , None ),
821
826
man = (skip , None ),
822
827
)
823
828
829
+ # ThebeSourceNode holds the source code and is rendered if
830
+ # hide-code is not specified. For HTML it is always rendered,
831
+ # but hidden using the stylesheet
824
832
app .add_node (
825
833
ThebeSourceNode ,
826
- html = (visit_widget_html , None ),
834
+ html = (visit_element_html , None ),
827
835
latex = render_thebe_source ,
828
836
textinfo = render_thebe_source ,
829
837
text = render_thebe_source ,
830
838
man = render_thebe_source ,
831
839
)
832
840
841
+ # ThebeOutputNode holds the output of the Jupyter cells
842
+ # and is rendered if hide-output is not specified.
833
843
app .add_node (
834
844
ThebeOutputNode ,
835
845
html = (visit_container_html , depart_container_html ),
@@ -839,9 +849,11 @@ def visit_thebe_source(self, node):
839
849
man = render_container ,
840
850
)
841
851
852
+ # ThebeButtonNode is the button that activates thebelab
853
+ # and is only rendered for the HTML builder
842
854
app .add_node (
843
855
ThebeButtonNode ,
844
- html = (visit_widget_html , None ),
856
+ html = (visit_element_html , None ),
845
857
latex = (skip , None ),
846
858
textinfo = (skip , None ),
847
859
text = (skip , None ),
0 commit comments