@@ -124,8 +124,8 @@ function get_jupytext_formats(notebook_tracker: INotebookTracker): Array<string>
124124 // return [];
125125
126126 const jupytext : IJupytextSection = ( JLAB4
127- ? model . getMetadata ( ' jupytext' )
128- : ( model . metadata as any ) ?. get ( 'jupytext' ) ) as unknown as IJupytextSection ;
127+ ? ( model as any ) . getMetadata ( " jupytext" )
128+ : ( model . metadata as any ) ?. get ( 'jupytext' ) ) as IJupytextSection ;
129129 if ( ! jupytext )
130130 return [ ] ;
131131 let formats : Array < string > = jupytext && jupytext . formats ? jupytext . formats . split ( ',' ) : [ ] ;
@@ -142,7 +142,7 @@ function get_selected_formats(notebook_tracker: INotebookTracker): Array<string>
142142 const model = notebook_tracker . currentWidget . context . model ;
143143
144144 const lang = ( JLAB4
145- ? model . getMetadata ( 'language_info' )
145+ ? ( model as any ) . getMetadata ( 'language_info' )
146146 : ( model . metadata as any ) ?. get ( 'language_info' )
147147 ) as nbformat . ILanguageInfoMetadata ;
148148 if ( lang && lang . file_extension ) {
@@ -175,8 +175,8 @@ function get_selected_formats(notebook_tracker: INotebookTracker): Array<string>
175175 // if (notebook_tracker.currentWidget.context.model.metadata.has("jupytext")) {
176176 const model = notebook_tracker . currentWidget . context . model ;
177177 const jupytext : IJupytextSection = ( JLAB4
178- ? model . getMetadata ( 'jupytext' )
179- : ( model . metadata as any ) ?. get ( 'jupytext' ) ) as unknown as IJupytextSection ;
178+ ? ( model as any ) . getMetadata ( 'jupytext' )
179+ : ( model . metadata as any ) ?. get ( 'jupytext' ) ) as IJupytextSection ;
180180 if ( jupytext && jupytext . text_representation && jupytext . text_representation . format_name )
181181 format_name = jupytext . text_representation . format_name ;
182182 // }
@@ -225,7 +225,7 @@ const extension: JupyterFrontEndPlugin<void> = {
225225 JLAB4 = parseInt ( app_numbers [ 0 ] ) >= 4 ;
226226 }
227227 }
228- console . log ( "JupyterLab extension jupyterlab- jupytext is activated!" ) ;
228+ console . log ( "JupyterLab extension jupytext is activated!" ) ;
229229 console . debug ( `JLAB4=${ JLAB4 } ` ) ;
230230 const trans = ( translator ?? nullTranslator ) . load ( "jupytext" ) ;
231231
@@ -270,9 +270,9 @@ const extension: JupyterFrontEndPlugin<void> = {
270270 return ;
271271 const model = notebookTracker . currentWidget . context . model ;
272272 const jupytext : IJupytextSection = ( JLAB4
273- ? model . getMetadata ( 'jupytext' )
273+ ? ( model as any ) . getMetadata ( 'jupytext' )
274274 : ( model . metadata as any ) ?. get ( 'jupytext' )
275- ) as unknown as IJupytextSection ;
275+ ) as IJupytextSection ;
276276 let formats : Array < string > = get_selected_formats ( notebookTracker ) ;
277277
278278 // Toggle the selected format
@@ -341,12 +341,9 @@ const extension: JupyterFrontEndPlugin<void> = {
341341 }
342342
343343 if ( formats . length === 0 ) {
344- if (
345- ! notebookTracker . currentWidget . context . model . getMetadata (
346- "jupytext"
347- )
348- )
349- return ;
344+ // an older version was re-fetching the jupytext metadata here
345+ // but this is not necessary, as the metadata is already available
346+ if ( ! jupytext ) return ;
350347
351348 if ( jupytext . formats ) {
352349 delete jupytext . formats ;
@@ -355,7 +352,7 @@ const extension: JupyterFrontEndPlugin<void> = {
355352 if ( Object . keys ( jupytext ) . length == 0 ) {
356353 const model = notebookTracker . currentWidget . context . model ;
357354 JLAB4
358- ? model . deleteMetadata ( "jupytext" )
355+ ? ( model as any ) . deleteMetadata ( "jupytext" )
359356 : ( model . metadata as any ) . delete ( "jupytext" ) ;
360357 }
361358 return ;
@@ -366,7 +363,7 @@ const extension: JupyterFrontEndPlugin<void> = {
366363 else {
367364 const model = notebookTracker . currentWidget . context . model ;
368365 JLAB4
369- ? model . setMetadata ( "jupytext" , { formats : formats . join ( ) } )
366+ ? ( model as any ) . setMetadata ( "jupytext" , { formats : formats . join ( ) } )
370367 : ( model . metadata as any ) ?. set ( { formats : formats . join ( ) } ) ;
371368 }
372369 }
@@ -406,7 +403,7 @@ const extension: JupyterFrontEndPlugin<void> = {
406403
407404 const model = notebookTracker . currentWidget . context . model ;
408405 const jupytext_metadata = JLAB4
409- ? model . getMetadata ( "jupytext" )
406+ ? ( model as any ) . getMetadata ( "jupytext" )
410407 : ( model . metadata as any ) ?. get ( "jupytext" )
411408 if ( ! jupytext_metadata )
412409 return false ;
@@ -424,7 +421,7 @@ const extension: JupyterFrontEndPlugin<void> = {
424421
425422 const model = notebookTracker . currentWidget . context . model ;
426423 const jupytext_metadata = JLAB4
427- ? model . getMetadata ( "jupytext" )
424+ ? ( model as any ) . getMetadata ( "jupytext" )
428425 : ( model . metadata as any ) ?. get ( "jupytext" )
429426 if ( ! jupytext_metadata )
430427 return false ;
@@ -446,7 +443,7 @@ const extension: JupyterFrontEndPlugin<void> = {
446443
447444 const model = notebookTracker . currentWidget . context . model ;
448445 const jupytext_metadata = JLAB4
449- ? model . getMetadata ( "jupytext" )
446+ ? ( model as any ) . getMetadata ( "jupytext" )
450447 : ( model . metadata as any ) ?. get ( "jupytext" )
451448 if ( ! jupytext_metadata )
452449 return false ;
@@ -499,7 +496,7 @@ const extension: JupyterFrontEndPlugin<void> = {
499496 // Mirror: https://github.com/jupyterlab/jupyterlab/blob/8a8c3752564f37493d4eb6b4c59008027fa83880/packages/notebook-extension/src/index.ts#L860
500497 const factory = new NotebookWidgetFactory ( {
501498 name : "Jupytext Notebook" ,
502- label : trans . __ ( "Jupytext Notebook" ) ,
499+ label : trans . __ ( "Jupytext Notebook" ) , // mandatory in jlab4 (not in jlab3)
503500 fileTypes : [ "markdown" , "myst" , "r-markdown" , "quarto" , "julia" , "python" , "r" ] ,
504501 modelName : notebookFactory . modelName ?? "notebook" ,
505502 preferKernel : notebookFactory . preferKernel ?? true ,
@@ -512,7 +509,7 @@ const extension: JupyterFrontEndPlugin<void> = {
512509 // sessionDialogs: sessionContextDialogs,
513510 toolbarFactory : notebookFactory . toolbarFactory ,
514511 // translator?: ITranslator,
515- } ) ;
512+ } as NotebookWidgetFactory . IOptions < NotebookPanel > ) ;
516513 app . docRegistry . addWidgetFactory ( factory ) ;
517514
518515 // Register widget created with the new factory in the notebook tracker
0 commit comments