Skip to content
This repository has been archived by the owner on Jul 30, 2023. It is now read-only.

rough & minimal changes to get index.ts to compile #4

Merged
merged 1 commit into from
Jun 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,11 @@ const LANGUAGE_INDEPENDENT_NOTEBOOK_EXTENSIONS = ["ipynb", "md", "Rmd", "qmd"];
function get_jupytext_formats(notebook_tracker: INotebookTracker): Array<string> {
if (!notebook_tracker.currentWidget) return [];

if (!notebook_tracker.currentWidget.context.model.metadata.has("jupytext"))
return [];

const jupytext: JupytextSection = (notebook_tracker.currentWidget.context.model.metadata.get(
const jupytext: JupytextSection = (notebook_tracker.currentWidget.context.model.getMetadata(
"jupytext"
) as unknown) as JupytextSection;
if ( ! jupytext )
return [];
let formats: Array<string> = jupytext && jupytext.formats ? jupytext.formats.split(',') : [];
return formats.filter(function (fmt) {
return fmt !== '';
Expand All @@ -126,7 +125,7 @@ function get_selected_formats(notebook_tracker: INotebookTracker): Array<string>

let formats = get_jupytext_formats(notebook_tracker);

const lang = notebook_tracker.currentWidget.context.model.metadata.get(
const lang = notebook_tracker.currentWidget.context.model.getMetadata(
"language_info"
) as nbformat.ILanguageInfoMetadata;
if (lang && lang.file_extension) {
Expand Down Expand Up @@ -155,14 +154,13 @@ function get_selected_formats(notebook_tracker: INotebookTracker): Array<string>
formats.push(notebook_extension);
else {
let format_name = 'light';
if (notebook_tracker.currentWidget.context.model.metadata.has("jupytext")) {
const jupytext: JupytextSection = (notebook_tracker.currentWidget.context.model.metadata.get(
// if (notebook_tracker.currentWidget.context.model.metadata.has("jupytext")) {
const jupytext: JupytextSection = (notebook_tracker.currentWidget.context.model.getMetadata(
"jupytext"
) as unknown) as JupytextSection;

if (jupytext && jupytext.text_representation && jupytext.text_representation.format_name)
format_name = jupytext.text_representation.format_name;
}
// }
formats.push('auto:' + format_name);
}
return formats;
Expand Down Expand Up @@ -237,7 +235,9 @@ const extension: JupyterFrontEndPlugin<void> = {
return true;
},
execute: () => {
const jupytext: JupytextSection = (notebookTracker.currentWidget.context.model.metadata.get(
if ( notebookTracker.currentWidget === null)
return;
const jupytext: JupytextSection = (notebookTracker.currentWidget.context.model.getMetadata(
"jupytext"
) as unknown) as JupytextSection;
let formats: Array<string> = get_selected_formats(notebookTracker);
Expand All @@ -253,8 +253,8 @@ const extension: JupyterFrontEndPlugin<void> = {
);
return;
}
// Toggle the selected format
let notebook_extension: string = notebookTracker.currentWidget.context.path.split('.').pop();
// Toggle the selected format
let notebook_extension: string = notebookTracker.currentWidget.context.path.split('.').pop() as string;
notebook_extension = LANGUAGE_INDEPENDENT_NOTEBOOK_EXTENSIONS.indexOf(notebook_extension) == -1 ? 'auto' : notebook_extension;

// Toggle the selected format
Expand Down Expand Up @@ -309,7 +309,7 @@ const extension: JupyterFrontEndPlugin<void> = {

if (formats.length === 0) {
if (
!notebookTracker.currentWidget.context.model.metadata.has(
!notebookTracker.currentWidget.context.model.getMetadata(
"jupytext"
)
)
Expand All @@ -320,7 +320,7 @@ const extension: JupyterFrontEndPlugin<void> = {
}

if (Object.keys(jupytext).length == 0)
notebookTracker.currentWidget.context.model.metadata.delete(
notebookTracker.currentWidget.context.model.deleteMetadata(
"jupytext"
);
return;
Expand All @@ -329,7 +329,7 @@ const extension: JupyterFrontEndPlugin<void> = {
// set the desired format
if (jupytext) jupytext.formats = formats.join();
else
notebookTracker.currentWidget.context.model.metadata.set(
notebookTracker.currentWidget.context.model.setMetadata(
"jupytext",
{ formats: formats.join() });
}
Expand Down Expand Up @@ -367,10 +367,10 @@ const extension: JupyterFrontEndPlugin<void> = {
if (!notebookTracker.currentWidget)
return false;

if (!notebookTracker.currentWidget.context.model.metadata.has("jupytext"))
if (!notebookTracker.currentWidget.context.model.getMetadata("jupytext"))
return false;

const jupytext: JupytextSection = (notebookTracker.currentWidget.context.model.metadata.get("jupytext") as unknown) as JupytextSection;
const jupytext: JupytextSection = (notebookTracker.currentWidget.context.model.getMetadata("jupytext") as unknown) as JupytextSection;

if (jupytext.notebook_metadata_filter === '-all')
return false;
Expand All @@ -381,10 +381,10 @@ const extension: JupyterFrontEndPlugin<void> = {
if (!notebookTracker.currentWidget)
return false;

if (!notebookTracker.currentWidget.context.model.metadata.has("jupytext"))
if (!notebookTracker.currentWidget.context.model.getMetadata("jupytext"))
return false;

const jupytext: JupytextSection = (notebookTracker.currentWidget.context.model.metadata.get("jupytext") as unknown) as JupytextSection;
const jupytext: JupytextSection = (notebookTracker.currentWidget.context.model.getMetadata("jupytext") as unknown) as JupytextSection;

if (jupytext.notebook_metadata_filter === undefined)
return true;
Expand All @@ -399,10 +399,10 @@ const extension: JupyterFrontEndPlugin<void> = {
if (!notebookTracker.currentWidget)
return;

if (!notebookTracker.currentWidget.context.model.metadata.has("jupytext"))
if (!notebookTracker.currentWidget.context.model.getMetadata("jupytext"))
return;

const jupytext: JupytextSection = (notebookTracker.currentWidget.context.model.metadata.get("jupytext") as unknown) as JupytextSection;
const jupytext: JupytextSection = (notebookTracker.currentWidget.context.model.getMetadata("jupytext") as unknown) as JupytextSection;

if (jupytext.notebook_metadata_filter) {
delete jupytext.notebook_metadata_filter;
Expand Down Expand Up @@ -460,9 +460,9 @@ const extension: JupyterFrontEndPlugin<void> = {
editorConfig: notebookFactory.editorConfig,
notebookConfig: notebookFactory.notebookConfig,
mimeTypeService: editorServices.mimeTypeService,
sessionDialogs: sessionContextDialogs,
// sessionDialogs: sessionContextDialogs,
toolbarFactory: notebookFactory.toolbarFactory,
translator,
// translator?: ITranslator,
});
app.docRegistry.addWidgetFactory(factory);

Expand Down