Skip to content

Commit 75944fd

Browse files
committed
Use notebook language for thebelab cells
1 parent d41907b commit 75944fd

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

jupyter_sphinx/execute.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,9 @@ def html(self):
277277
if self['code_below']:
278278
code_class += ' thebelab-below'
279279
code = self.astext()
280-
return '<pre class="{}" data-executable="true" data-language="python">{}</pre>'\
281-
.format(code_class, code)
280+
language = self['language']
281+
return '<pre class="{}" data-executable="true" data-language="{}">{}</pre>'\
282+
.format(code_class, language, code)
282283

283284

284285
class ThebeOutputNode(docutils.nodes.container):
@@ -395,6 +396,11 @@ def apply(self):
395396
# include the path to the output file.
396397
write_notebook_output(notebook, output_dir, file_name)
397398

399+
try:
400+
cm_language = notebook.metadata.language_info.codemirror_mode.name
401+
except AttributeError:
402+
cm_language = notebook.metadata.kernelspec.language
403+
398404
# Add doctree nodes for cell outputs.
399405
for node, cell in zip(nodes, notebook.cells):
400406
output_nodes = cell_output_to_nodes(
@@ -403,7 +409,7 @@ def apply(self):
403409
sphinx_abs_dir(self.env),
404410
thebe_config
405411
)
406-
attach_outputs(output_nodes, node, thebe_config)
412+
attach_outputs(output_nodes, node, thebe_config, cm_language)
407413

408414
if contains_widgets(notebook):
409415
doctree.append(JupyterWidgetStateNode(state=get_widgets(notebook)))
@@ -538,12 +544,13 @@ def cell_output_to_nodes(cell, data_priority, dir, thebe_config):
538544
return to_add
539545

540546

541-
def attach_outputs(output_nodes, node, thebe_config):
547+
def attach_outputs(output_nodes, node, thebe_config, cm_language):
542548
if thebe_config and not node.attributes['no_thebelab']:
543549
source = node.children[0]
544550

545551
thebe_source = ThebeSourceNode(hide_code=node.attributes['hide_code'],
546-
code_below=node.attributes['code_below'])
552+
code_below=node.attributes['code_below'],
553+
language=cm_language)
547554
thebe_source.children = [source]
548555

549556
node.children = [thebe_source]

0 commit comments

Comments
 (0)