Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit 49b9ae3

Browse files
authored
Merge pull request #296 from jweill-aws/shorter-title
Strip .ipynb extension for display in header and tab title
2 parents 4fd58de + f5f11b4 commit 49b9ae3

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

packages/application-extension/src/index.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ const EDITOR_FACTORY = 'Editor';
5555
*/
5656
const TREE_PATTERN = new RegExp('/(notebooks|edit)/(.*)');
5757

58+
/**
59+
* A regular expression to suppress the file extension from display for .ipynb files.
60+
*/
61+
const STRIP_IPYNB = /\.ipynb$/;
62+
5863
/**
5964
* The command IDs used by the application plugin.
6065
*/
@@ -383,15 +388,16 @@ const tabTitle: JupyterFrontEndPlugin<void> = {
383388
const title =
384389
current.sessionContext.path || current.sessionContext.name;
385390
const basename = PathExt.basename(title);
386-
document.title = basename;
391+
// Strip the ".ipynb" suffix from filenames for display in tab titles.
392+
document.title = basename.replace(STRIP_IPYNB, '');
387393
};
388394
current.sessionContext.sessionChanged.connect(update);
389395
update();
390396
return;
391397
} else if (current instanceof DocumentWidget) {
392398
const update = () => {
393399
const basename = PathExt.basename(current.context.path);
394-
document.title = basename;
400+
document.title = basename.replace(STRIP_IPYNB, '');
395401
};
396402
current.context.pathChanged.connect(update);
397403
update();
@@ -435,7 +441,7 @@ const title: JupyterFrontEndPlugin<void> = {
435441
}
436442

437443
const h = document.createElement('h1');
438-
h.textContent = current.title.label;
444+
h.textContent = current.title.label.replace(STRIP_IPYNB, '');
439445
widget.node.appendChild(h);
440446
widget.node.style.marginLeft = '10px';
441447
if (!docManager) {
@@ -468,7 +474,8 @@ const title: JupyterFrontEndPlugin<void> = {
468474

469475
const newPath = current.context.path ?? result.path;
470476
const basename = PathExt.basename(newPath);
471-
h.textContent = basename;
477+
478+
h.textContent = basename.replace(STRIP_IPYNB, '');
472479
if (!router) {
473480
return;
474481
}

ui-tests/test/notebook.spec.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ test.describe('Notebook', () => {
3434
const notebook = `${tmpPath}/${NOTEBOOK}`;
3535
await page.goto(`notebooks/${notebook}`);
3636

37-
// Click on the title
38-
await page.click('text="example.ipynb"');
37+
// Click on the title (with .ipynb extension stripped)
38+
await page.click('text="example"');
3939

4040
// Rename in the input dialog
4141
const newName = 'test.ipynb';
42+
const newNameStripped = 'test';
4243
await page.fill(
4344
`//div[normalize-space(.)='File Path${notebook}New Name']/input`,
4445
newName
@@ -52,6 +53,6 @@ test.describe('Notebook', () => {
5253

5354
// Check the URL contains the new name
5455
const url = page.url();
55-
expect(url).toContain(newName);
56+
expect(url).toContain(newNameStripped);
5657
});
5758
});

0 commit comments

Comments
 (0)