|
1 | | -From 5bffbe38302c695123779f87300d84090b4bd118 Mon Sep 17 00:00:00 2001 |
| 1 | +From 7951c3183b422bc7afe115952ef7ae15b79e45d3 Mon Sep 17 00:00:00 2001 |
2 | 2 | From: Kwankyu Lee <ekwankyu@gmail.com> |
3 | 3 | Date: Mon, 28 Aug 2023 00:18:59 +0900 |
4 | 4 | Subject: [PATCH] Patch for sage live doc |
5 | 5 |
|
6 | 6 | --- |
7 | 7 | jupyter_sphinx/__init__.py | 4 ++-- |
8 | | - jupyter_sphinx/execute.py | 11 +++++++++++ |
9 | | - 2 files changed, 13 insertions(+), 2 deletions(-) |
| 8 | + jupyter_sphinx/execute.py | 17 +++++++++++++++++ |
| 9 | + 2 files changed, 19 insertions(+), 2 deletions(-) |
10 | 10 |
|
11 | 11 | diff --git a/jupyter_sphinx/__init__.py b/jupyter_sphinx/__init__.py |
12 | | -index 34af884..b7ca8ee 100644 |
| 12 | +index 34af884..920131c 100644 |
13 | 13 | --- a/jupyter_sphinx/__init__.py |
14 | 14 | +++ b/jupyter_sphinx/__init__.py |
15 | 15 | @@ -31,7 +31,7 @@ from .thebelab import ThebeButton, ThebeButtonNode, ThebeOutputNode, ThebeSource |
16 | 16 | REQUIRE_URL_DEFAULT = ( |
17 | 17 | "https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js" |
18 | 18 | ) |
19 | 19 | -THEBELAB_URL_DEFAULT = "https://unpkg.com/thebelab@^0.4.0" |
20 | | -+THEBELAB_URL_DEFAULT = "https://unpkg.com/thebe@latest/lib/index.js" |
21 | | - |
| 20 | ++THEBELAB_URL_DEFAULT = "https://unpkg.com/thebe@0.8.2/lib/index.js" |
| 21 | + |
22 | 22 | logger = logging.getLogger(__name__) |
23 | | - |
| 23 | + |
24 | 24 | @@ -186,7 +186,7 @@ def setup(app): |
25 | 25 | app.add_config_value("jupyter_sphinx_embed_url", None, "html") |
26 | | - |
| 26 | + |
27 | 27 | # thebelab config, can be either a filename or a dict |
28 | 28 | - app.add_config_value("jupyter_sphinx_thebelab_config", None, "html") |
29 | 29 | + app.add_config_value("jupyter_sphinx_thebelab_config", None, "env") |
30 | 30 | app.add_config_value("jupyter_sphinx_thebelab_url", THEBELAB_URL_DEFAULT, "html") |
31 | | - |
| 31 | + |
32 | 32 | # linenos config |
33 | 33 | diff --git a/jupyter_sphinx/execute.py b/jupyter_sphinx/execute.py |
34 | | -index 558a26b..de44455 100644 |
| 34 | +index cb473cf..898d86b 100644 |
35 | 35 | --- a/jupyter_sphinx/execute.py |
36 | 36 | +++ b/jupyter_sphinx/execute.py |
37 | | -@@ -152,6 +152,17 @@ class ExecuteJupyterCells(SphinxTransform): |
| 37 | +@@ -152,6 +152,23 @@ class ExecuteJupyterCells(SphinxTransform): |
38 | 38 | kernel_name = default_kernel |
39 | 39 | file_name = next(default_names) |
40 | | - |
| 40 | + |
41 | 41 | + # Save time when jupyter notebook execution is not necessary |
42 | | -+ if not any(not "execute" in node or node["execute"] for node in nodes): |
43 | | -+ # mimics empty cell output for each node |
| 42 | ++ if all("execute" in node and not node["execute"] for node in nodes): |
| 43 | ++ notebook = blank_nb(kernel_name) |
| 44 | ++ try: |
| 45 | ++ cm_language = notebook.metadata.language_info.codemirror_mode.name |
| 46 | ++ except AttributeError: |
| 47 | ++ cm_language = notebook.metadata.kernelspec.language |
| 48 | ++ # Mimic empty cell output for each node |
44 | 49 | + for node in nodes: |
45 | 50 | + source = node.children[0] |
46 | 51 | + source.attributes["classes"].append("code_cell") |
47 | | -+ node.attributes["cm_language"] = kernel_name |
48 | | -+ node += CellOutputNode(classes=["cell_output"]) |
| 52 | ++ node.attributes["cm_language"] = cm_language |
| 53 | ++ if len(node.children) < 2: |
| 54 | ++ node += CellOutputNode(classes=["cell_output"]) |
49 | 55 | + apply_styling(node, thebe_config) |
50 | 56 | + continue |
51 | 57 | + |
52 | 58 | # Add empty placeholder cells for non-executed nodes so nodes |
53 | 59 | # and cells can be zipped and the provided input/output |
54 | 60 | # can be inserted later |
55 | | --- |
56 | | -2.42.0 |
| 61 | +-- |
| 62 | +2.44.0 |
57 | 63 |
|
0 commit comments