Skip to content

Commit 60758ea

Browse files
authored
Merge pull request #151 from akhmerov/issue-126
properly store cm_language in node attributes
2 parents f20eab0 + d91537f commit 60758ea

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

jupyter_sphinx/ast.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def cell_output_to_nodes(outputs, data_priority, write_stderr, out_dir,
370370
return to_add
371371

372372

373-
def attach_outputs(output_nodes, node, thebe_config, cm_language):
373+
def attach_outputs(output_nodes, node, thebe_config):
374374
if not node.attributes["hide_code"]: # only add css if code is displayed
375375
classes = node.attributes.get("classes", [])
376376
classes += ["jupyter_container"]
@@ -384,7 +384,7 @@ def attach_outputs(output_nodes, node, thebe_config, cm_language):
384384
thebe_source = ThebeSourceNode(
385385
hide_code=node.attributes["hide_code"],
386386
code_below=node.attributes["code_below"],
387-
language=cm_language,
387+
language=node.attributes["cm_language"],
388388
)
389389
thebe_source.children = [source]
390390
input_node.children = [thebe_source]
@@ -451,7 +451,7 @@ def apply(self):
451451
thebe_config,
452452
)
453453
# Remove the outputbundlenode and we'll attach the outputs next
454-
attach_outputs(output_nodes, cell_node, thebe_config, cell_node.cm_language)
454+
attach_outputs(output_nodes, cell_node, thebe_config)
455455

456456
# Image collect extra nodes from cell outputs that we need to process
457457
for node in self.document.traverse(image):

jupyter_sphinx/execute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def apply(self):
214214
except AttributeError:
215215
cm_language = notebook.metadata.kernelspec.language
216216
for node in nodes:
217-
node.cm_language = cm_language
217+
node.attributes["cm_language"] = cm_language
218218

219219
# Add doctree nodes for cell outputs.
220220
for node, cell in zip(nodes, notebook.cells):

tests/test_execute.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ def doctree():
3333
syspath = sys.path[:]
3434

3535
def doctree(
36-
source, config=None, return_warnings=False, entrypoint="jupyter_sphinx"
36+
source,
37+
config=None,
38+
return_warnings=False,
39+
entrypoint="jupyter_sphinx",
40+
buildername='html'
3741
):
3842
src_dir = Path(tempfile.mkdtemp())
3943
source_trees.append(src_dir)
@@ -45,7 +49,12 @@ def doctree(
4549
(src_dir / "contents.rst").write_text(source, encoding = "utf8")
4650

4751
warnings = StringIO()
48-
app = SphinxTestApp(srcdir=path(src_dir.as_posix()), status=StringIO(), warning=warnings)
52+
app = SphinxTestApp(
53+
srcdir=path(src_dir.as_posix()),
54+
status=StringIO(),
55+
warning=warnings,
56+
buildername=buildername
57+
)
4958
apps.append(app)
5059
app.build()
5160

@@ -65,13 +74,14 @@ def doctree(
6574
shutil.rmtree(tree)
6675

6776

68-
def test_basic(doctree):
77+
@pytest.mark.parametrize('buildername', ['html', 'singlehtml'])
78+
def test_basic(doctree, buildername):
6979
source = """
7080
.. jupyter-execute::
7181
7282
2 + 2
7383
"""
74-
tree = doctree(source)
84+
tree = doctree(source, buildername=buildername)
7585
(cell,) = tree.traverse(JupyterCellNode)
7686
(cellinput, celloutput) = cell.children
7787
assert cell.attributes["code_below"] is False

0 commit comments

Comments
 (0)