Skip to content

Commit 9bae988

Browse files
authored
Merge pull request #169 from akhmerov/builder-display-priority
Allow mime bundles display different content based on the builder
2 parents fe31d44 + 67b44ce commit 9bae988

File tree

5 files changed

+229
-179
lines changed

5 files changed

+229
-179
lines changed

doc/source/index.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,22 @@ jupyter_execute_default_kernel
437437
The default is ``python3``.
438438

439439

440-
jupyter_execute_data_priority
440+
render_priority_html
441441

442-
The display priority of different output mimetypes. Mimetypes earlier in the data priority
442+
The priority of different output mimetypes for displaying in HTML output. Mimetypes earlier in the data priority
443443
list are preferred over later ones. This is relevant if a code cell produces an output
444444
that has several possible representations (e.g. description text or an image).
445+
Please open an issue if you find a mimetype that isn't supported, but should be.
445446
The default is
446447
``['application/vnd.jupyter.widget-view+json', 'text/html', 'image/svg+xml', 'image/png', 'image/jpeg', 'text/latex', 'text/plain']``.
447448

448449

450+
render_priority_latex
451+
452+
Same, as ``render_priority_html``, but for latex. The default is
453+
``['image/svg+xml', 'image/png', 'image/jpeg', 'text/latex', 'text/plain']``.
454+
455+
449456
jupyter_execute_kwargs
450457

451458
Keyword arguments to pass to ``nbconvert.preprocessors.execute.executenb``, which controls how
@@ -469,6 +476,7 @@ Release 0.4.0
469476
- Allow adding inputs and outputs that are not executed using ``jupyter-input`` and ``jupyter-output`` directives.
470477
- Improve script handling by using ``nbconvert`` directly.
471478
- Remove deprecated enabling of the extension as ``jupyter_sphinx.execute``.
479+
- Implement different output priorities in HTML and LaTeX builders. In practice this allows to provide a better fallback in PDF output.
472480

473481
Release 0.3.0
474482
~~~~~~~~~~~~~

jupyter_sphinx/__init__.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
CellInputNode,
1818
CellOutput,
1919
CellOutputNode,
20-
CellOutputBundleNode,
20+
MimeBundleNode,
2121
JupyterKernelNode,
2222
JupyterWidgetViewNode,
2323
JupyterWidgetStateNode,
2424
WIDGET_VIEW_MIMETYPE,
2525
JupyterDownloadRole,
2626
CombineCellInputOutput,
27-
CellOutputsToNodes,
2827
)
2928
from .execute import JupyterKernel, ExecuteJupyterCells
3029
from .thebelab import ThebeButton, ThebeButtonNode, ThebeOutputNode, ThebeSourceNode
@@ -152,7 +151,7 @@ def setup(app):
152151
)
153152
app.add_config_value("jupyter_execute_default_kernel", "python3", "env")
154153
app.add_config_value(
155-
"jupyter_execute_data_priority",
154+
"render_priority_html",
156155
[
157156
WIDGET_VIEW_MIMETYPE,
158157
"application/javascript",
@@ -165,6 +164,17 @@ def setup(app):
165164
],
166165
"env",
167166
)
167+
app.add_config_value(
168+
"render_priority_latex",
169+
[
170+
"image/svg+xml",
171+
"image/png",
172+
"image/jpeg",
173+
"text/latex",
174+
"text/plain",
175+
],
176+
"env",
177+
)
168178

169179
# ipywidgets config
170180
app.add_config_value("jupyter_sphinx_require_url", REQUIRE_URL_DEFAULT, "html")
@@ -190,7 +200,7 @@ def setup(app):
190200
)
191201

192202
# Register our container nodes, these should behave just like a regular container
193-
for node in [JupyterCellNode, CellInputNode, CellOutputNode]:
203+
for node in [JupyterCellNode, CellInputNode, CellOutputNode, MimeBundleNode]:
194204
app.add_node(
195205
node,
196206
override=True,
@@ -201,18 +211,6 @@ def setup(app):
201211
man=(render_container),
202212
)
203213

204-
# Register the output bundle node.
205-
# No translators should touch this node because we'll replace it in a post-transform
206-
app.add_node(
207-
CellOutputBundleNode,
208-
override=True,
209-
html=(halt, None),
210-
latex=(halt, None),
211-
textinfo=(halt, None),
212-
text=(halt, None),
213-
man=(halt, None),
214-
)
215-
216214
# JupyterWidgetViewNode holds widget view JSON,
217215
# but is only rendered properly in HTML documents.
218216
app.add_node(
@@ -278,7 +276,6 @@ def setup(app):
278276
app.add_role("jupyter-download:script", JupyterDownloadRole())
279277
app.add_transform(CombineCellInputOutput)
280278
app.add_transform(ExecuteJupyterCells)
281-
app.add_transform(CellOutputsToNodes)
282279

283280
# For syntax highlighting
284281
app.add_lexer("ipythontb", IPythonTracebackLexer)

0 commit comments

Comments
 (0)