@@ -192,7 +192,37 @@ const plugin: JupyterFrontEndPlugin<void> = {
192192 commands . addCommand ( Commands . downloadNotebookCommand , {
193193 label : 'Download as a notebook' ,
194194 execute : args => {
195- // Execute the built-in download command
195+ // Clear all sharing-specific metadata before download
196+ const panel = readonlyTracker . currentWidget ?? tracker . currentWidget ;
197+
198+ if ( ! panel ) {
199+ console . warn ( 'No active notebook to download' ) ;
200+ return ;
201+ }
202+
203+ const content = panel . context . model . toJSON ( ) as INotebookContent ;
204+
205+ // Remove sharing-specific metadata
206+ const purgedMetadata = { ...content . metadata } ;
207+ delete purgedMetadata . isSharedNotebook ;
208+ delete purgedMetadata . sharedId ;
209+ delete purgedMetadata . readableId ;
210+ delete purgedMetadata . sharedName ;
211+ delete purgedMetadata . lastShared ;
212+
213+ // Ensure that we preserve kernelspec metadata if present
214+ const kernelSpec = content . metadata ?. kernelspec ;
215+ if ( kernelSpec ) {
216+ purgedMetadata . kernelspec = kernelSpec ;
217+ }
218+
219+ const cleanedContent : INotebookContent = {
220+ ...content ,
221+ metadata : purgedMetadata
222+ } ;
223+ panel . context . model . fromJSON ( cleanedContent ) ;
224+
225+ // Execute the built-in download command with the cleaned model
196226 return commands . execute ( 'docmanager:download' ) ;
197227 }
198228 } ) ;
@@ -427,7 +457,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
427457 delete purgedMetadata . sharedName ;
428458 delete purgedMetadata . lastShared ;
429459
430- // Ensure that we preserve kernelspec metadata
460+ // Ensure that we preserve kernelspec metadata if present
431461 const kernelSpec = originalContent . metadata ?. kernelspec ;
432462
433463 // Remove cell-level editable=false; as the notebook has
0 commit comments