From b07f59a1652a7601e7e465a854d4e4e3a2ab6bce Mon Sep 17 00:00:00 2001 From: Jason Weill Date: Wed, 1 Dec 2021 14:57:26 -0800 Subject: [PATCH 1/4] Strip .ipynb extension for display --- packages/application-extension/src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/application-extension/src/index.ts b/packages/application-extension/src/index.ts index d85a7911..8f1f461a 100644 --- a/packages/application-extension/src/index.ts +++ b/packages/application-extension/src/index.ts @@ -468,7 +468,10 @@ const title: JupyterFrontEndPlugin = { const newPath = current.context.path ?? result.path; const basename = PathExt.basename(newPath); - h.textContent = basename; + // Don't show the file extension for .ipynb files. + const stripIpynb = /\.ipynb$/; + + h.textContent = basename.replace(stripIpynb, ''); if (!router) { return; } From 2a775aa304b6635d97de773039babf8bd7de5db6 Mon Sep 17 00:00:00 2001 From: Jason Weill Date: Wed, 1 Dec 2021 15:36:26 -0800 Subject: [PATCH 2/4] Strips extension from initial heading as well as updated heading --- packages/application-extension/src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/application-extension/src/index.ts b/packages/application-extension/src/index.ts index 8f1f461a..0db285ff 100644 --- a/packages/application-extension/src/index.ts +++ b/packages/application-extension/src/index.ts @@ -434,8 +434,11 @@ const title: JupyterFrontEndPlugin = { return; } + // Don't show the file extension for .ipynb files. + const stripIpynb = /\.ipynb$/; + const h = document.createElement('h1'); - h.textContent = current.title.label; + h.textContent = current.title.label.replace(stripIpynb, ''); widget.node.appendChild(h); widget.node.style.marginLeft = '10px'; if (!docManager) { @@ -468,8 +471,6 @@ const title: JupyterFrontEndPlugin = { const newPath = current.context.path ?? result.path; const basename = PathExt.basename(newPath); - // Don't show the file extension for .ipynb files. - const stripIpynb = /\.ipynb$/; h.textContent = basename.replace(stripIpynb, ''); if (!router) { From 11b126cb66dc4f1155de34db0505379ff91bdd86 Mon Sep 17 00:00:00 2001 From: Jason Weill Date: Wed, 1 Dec 2021 16:16:55 -0800 Subject: [PATCH 3/4] Updates UI test to expect new title --- ui-tests/test/notebook.spec.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ui-tests/test/notebook.spec.ts b/ui-tests/test/notebook.spec.ts index 7028b72f..f99e4edc 100644 --- a/ui-tests/test/notebook.spec.ts +++ b/ui-tests/test/notebook.spec.ts @@ -34,11 +34,12 @@ test.describe('Notebook', () => { const notebook = `${tmpPath}/${NOTEBOOK}`; await page.goto(`notebooks/${notebook}`); - // Click on the title - await page.click('text="example.ipynb"'); + // Click on the title (with .ipynb extension stripped) + await page.click('text="example"'); // Rename in the input dialog const newName = 'test.ipynb'; + const newNameStripped = 'test'; await page.fill( `//div[normalize-space(.)='File Path${notebook}New Name']/input`, newName @@ -52,6 +53,6 @@ test.describe('Notebook', () => { // Check the URL contains the new name const url = page.url(); - expect(url).toContain(newName); + expect(url).toContain(newNameStripped); }); }); From f5f11b46b666d6dbb5a8f14264819cf31ce798b2 Mon Sep 17 00:00:00 2001 From: Jason Weill Date: Thu, 2 Dec 2021 09:44:58 -0800 Subject: [PATCH 4/4] Strips .ipynb suffix from tab title --- packages/application-extension/src/index.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/application-extension/src/index.ts b/packages/application-extension/src/index.ts index 0db285ff..8c439e7c 100644 --- a/packages/application-extension/src/index.ts +++ b/packages/application-extension/src/index.ts @@ -55,6 +55,11 @@ const EDITOR_FACTORY = 'Editor'; */ const TREE_PATTERN = new RegExp('/(notebooks|edit)/(.*)'); +/** + * A regular expression to suppress the file extension from display for .ipynb files. + */ +const STRIP_IPYNB = /\.ipynb$/; + /** * The command IDs used by the application plugin. */ @@ -383,7 +388,8 @@ const tabTitle: JupyterFrontEndPlugin = { const title = current.sessionContext.path || current.sessionContext.name; const basename = PathExt.basename(title); - document.title = basename; + // Strip the ".ipynb" suffix from filenames for display in tab titles. + document.title = basename.replace(STRIP_IPYNB, ''); }; current.sessionContext.sessionChanged.connect(update); update(); @@ -391,7 +397,7 @@ const tabTitle: JupyterFrontEndPlugin = { } else if (current instanceof DocumentWidget) { const update = () => { const basename = PathExt.basename(current.context.path); - document.title = basename; + document.title = basename.replace(STRIP_IPYNB, ''); }; current.context.pathChanged.connect(update); update(); @@ -434,11 +440,8 @@ const title: JupyterFrontEndPlugin = { return; } - // Don't show the file extension for .ipynb files. - const stripIpynb = /\.ipynb$/; - const h = document.createElement('h1'); - h.textContent = current.title.label.replace(stripIpynb, ''); + h.textContent = current.title.label.replace(STRIP_IPYNB, ''); widget.node.appendChild(h); widget.node.style.marginLeft = '10px'; if (!docManager) { @@ -472,7 +475,7 @@ const title: JupyterFrontEndPlugin = { const newPath = current.context.path ?? result.path; const basename = PathExt.basename(newPath); - h.textContent = basename.replace(stripIpynb, ''); + h.textContent = basename.replace(STRIP_IPYNB, ''); if (!router) { return; }