@@ -277,8 +277,9 @@ def html(self):
277
277
if self ['code_below' ]:
278
278
code_class += ' thebelab-below'
279
279
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 )
282
283
283
284
284
285
class ThebeOutputNode (docutils .nodes .container ):
@@ -395,6 +396,11 @@ def apply(self):
395
396
# include the path to the output file.
396
397
write_notebook_output (notebook , output_dir , file_name )
397
398
399
+ try :
400
+ cm_language = notebook .metadata .language_info .codemirror_mode .name
401
+ except AttributeError :
402
+ cm_language = notebook .metadata .kernelspec .language
403
+
398
404
# Add doctree nodes for cell outputs.
399
405
for node , cell in zip (nodes , notebook .cells ):
400
406
output_nodes = cell_output_to_nodes (
@@ -403,7 +409,7 @@ def apply(self):
403
409
sphinx_abs_dir (self .env ),
404
410
thebe_config
405
411
)
406
- attach_outputs (output_nodes , node , thebe_config )
412
+ attach_outputs (output_nodes , node , thebe_config , cm_language )
407
413
408
414
if contains_widgets (notebook ):
409
415
doctree .append (JupyterWidgetStateNode (state = get_widgets (notebook )))
@@ -538,12 +544,13 @@ def cell_output_to_nodes(cell, data_priority, dir, thebe_config):
538
544
return to_add
539
545
540
546
541
- def attach_outputs (output_nodes , node , thebe_config ):
547
+ def attach_outputs (output_nodes , node , thebe_config , cm_language ):
542
548
if thebe_config and not node .attributes ['no_thebelab' ]:
543
549
source = node .children [0 ]
544
550
545
551
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 )
547
554
thebe_source .children = [source ]
548
555
549
556
node .children = [thebe_source ]
0 commit comments