@@ -206,7 +206,7 @@ def apply(self):
206
206
# Write certain cell outputs (e.g. images) to separate files, and
207
207
# modify the metadata of the associated cells in 'notebook' to
208
208
# include the path to the output file.
209
- write_notebook_output (notebook , output_dir , file_name )
209
+ write_notebook_output (notebook , output_dir , file_name , self . env . docname )
210
210
211
211
try :
212
212
cm_language = notebook .metadata .language_info .codemirror_mode .name
@@ -239,7 +239,7 @@ def execute_cells(kernel_name, cells, execute_kwargs):
239
239
return notebook
240
240
241
241
242
- def write_notebook_output (notebook , output_dir , notebook_name ):
242
+ def write_notebook_output (notebook , output_dir , notebook_name , location = None ):
243
243
"""Extract output from notebook cells and write to files in output_dir.
244
244
245
245
This also modifies 'notebook' in-place, adding metadata to each cell that
@@ -258,7 +258,13 @@ def write_notebook_output(notebook, output_dir, notebook_name):
258
258
)
259
259
# Write a script too. Note that utf-8 is the de facto
260
260
# standard encoding for notebooks.
261
- ext = notebook .metadata .language_info .file_extension
261
+ ext = notebook .metadata .get ("language_info" , {}).get ("file_extension" , None )
262
+ if ext is None :
263
+ ext = ".txt"
264
+ js .logger .warning (
265
+ "Notebook code has no file extension metadata, " "defaulting to `.txt`" ,
266
+ location = location ,
267
+ )
262
268
contents = "\n \n " .join (cell .source for cell in notebook .cells )
263
269
with open (os .path .join (output_dir , notebook_name + ext ), "w" ,
264
270
encoding = "utf8" ) as f :
0 commit comments