|
26 | 26 |
|
27 | 27 | logger = logging.getLogger(__name__)
|
28 | 28 |
|
| 29 | +############################################################################## |
| 30 | +# Constants and functions we'll use later |
29 | 31 |
|
| 32 | +# Used for nodes that do not need to be rendered |
| 33 | +def skip(self, node): |
| 34 | + raise docutils.nodes.SkipNode |
| 35 | + |
| 36 | +# Renders the children of a container |
| 37 | +render_container = ( |
| 38 | + lambda self, node: self.visit_container(node), |
| 39 | + lambda self, node: self.depart_container(node), |
| 40 | +) |
| 41 | + |
| 42 | +# Used to render the container and its children as HTML |
| 43 | +def visit_container_html(self, node): |
| 44 | + self.body.append(node.visit_html()) |
| 45 | + self.visit_container(node) |
| 46 | + |
| 47 | +def depart_container_html(self, node): |
| 48 | + self.depart_container(node) |
| 49 | + self.body.append(node.depart_html()) |
| 50 | + |
| 51 | +# Used to render an element node as HTML |
| 52 | +def visit_element_html(self, node): |
| 53 | + self.body.append(node.html()) |
| 54 | + raise docutils.nodes.SkipNode |
| 55 | + |
| 56 | +# Used to render the ThebeSourceNode conditionally for non-HTML builders |
| 57 | +def visit_thebe_source(self, node): |
| 58 | + if node["hide_code"]: |
| 59 | + raise docutils.nodes.SkipNode |
| 60 | + else: |
| 61 | + self.visit_container(node) |
| 62 | + |
| 63 | +render_thebe_source = ( |
| 64 | + visit_thebe_source, |
| 65 | + lambda self, node: self.depart_container(node), |
| 66 | +) |
| 67 | + |
| 68 | +############################################################################## |
| 69 | +# Sphinx callback functions |
30 | 70 | def builder_inited(app):
|
31 | 71 | """
|
32 | 72 | 2 cases
|
@@ -75,7 +115,9 @@ def build_finished(app, env):
|
75 | 115 | copy_asset(src, dst)
|
76 | 116 |
|
77 | 117 |
|
78 |
| -def _setup(app): |
| 118 | +############################################################################## |
| 119 | +# Main setup |
| 120 | +def setup(app): |
79 | 121 | """A temporary setup function so that we can use it here and in execute.
|
80 | 122 |
|
81 | 123 | This should be removed and converted into `setup` after a deprecation
|
@@ -110,49 +152,12 @@ def _setup(app):
|
110 | 152 |
|
111 | 153 | # thebelab config, can be either a filename or a dict
|
112 | 154 | app.add_config_value("jupyter_sphinx_thebelab_config", None, "html")
|
113 |
| - |
114 | 155 | app.add_config_value("jupyter_sphinx_thebelab_url", THEBELAB_URL_DEFAULT, "html")
|
115 | 156 |
|
116 | 157 | # linenos config
|
117 | 158 | app.add_config_value("jupyter_sphinx_linenos", False, "env")
|
118 | 159 | app.add_config_value("jupyter_sphinx_continue_linenos", False, "env")
|
119 | 160 |
|
120 |
| - # Used for nodes that do not need to be rendered |
121 |
| - def skip(self, node): |
122 |
| - raise docutils.nodes.SkipNode |
123 |
| - |
124 |
| - # Renders the children of a container |
125 |
| - render_container = ( |
126 |
| - lambda self, node: self.visit_container(node), |
127 |
| - lambda self, node: self.depart_container(node), |
128 |
| - ) |
129 |
| - |
130 |
| - # Used to render the container and its children as HTML |
131 |
| - def visit_container_html(self, node): |
132 |
| - self.body.append(node.visit_html()) |
133 |
| - self.visit_container(node) |
134 |
| - |
135 |
| - def depart_container_html(self, node): |
136 |
| - self.depart_container(node) |
137 |
| - self.body.append(node.depart_html()) |
138 |
| - |
139 |
| - # Used to render an element node as HTML |
140 |
| - def visit_element_html(self, node): |
141 |
| - self.body.append(node.html()) |
142 |
| - raise docutils.nodes.SkipNode |
143 |
| - |
144 |
| - # Used to render the ThebeSourceNode conditionally for non-HTML builders |
145 |
| - def visit_thebe_source(self, node): |
146 |
| - if node["hide_code"]: |
147 |
| - raise docutils.nodes.SkipNode |
148 |
| - else: |
149 |
| - self.visit_container(node) |
150 |
| - |
151 |
| - render_thebe_source = ( |
152 |
| - visit_thebe_source, |
153 |
| - lambda self, node: self.depart_container(node), |
154 |
| - ) |
155 |
| - |
156 | 161 | # JupyterKernelNode is just a doctree marker for the
|
157 | 162 | # ExecuteJupyterCells transform, so we don't actually render it.
|
158 | 163 | app.add_node(
|
@@ -245,12 +250,3 @@ def visit_thebe_source(self, node):
|
245 | 250 | app.connect("build-finished", build_finished)
|
246 | 251 |
|
247 | 252 | return {"version": __version__, "parallel_read_safe": True}
|
248 |
| - |
249 |
| - |
250 |
| -def setup(app): |
251 |
| - """The main setup function. |
252 |
| -
|
253 |
| - This should be replaced with `_setup` after a deprecation cycle. |
254 |
| - """ |
255 |
| - out = _setup(app) |
256 |
| - return out |
0 commit comments