From ae1be7b3b5f33887e37e5868bf77be9268ce3bb2 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Mon, 22 Feb 2021 14:14:20 +0100 Subject: [PATCH 1/4] Add redirect handler to open non-notebook files --- nbclassic/notebookapp.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nbclassic/notebookapp.py b/nbclassic/notebookapp.py index f49f3c093..b801716ad 100644 --- a/nbclassic/notebookapp.py +++ b/nbclassic/notebookapp.py @@ -14,6 +14,7 @@ import gettext from jinja2 import Environment, FileSystemLoader +from tornado.web import RedirectHandler import notebook from notebook import ( @@ -218,6 +219,17 @@ def initialize_handlers(self): """Load the (URL pattern, handler) tuples for each component.""" # Order matters. The first handler to match the URL will handle the request. handlers = [] + + # Add a redirect from /notebooks to /edit + # for opening non-ipynb files in edit mode. + handlers.append( + ( + rf"/({self.file_url_prefix})/(.*)\.(((?!ipynb)).*)", + RedirectHandler, + {"url": "/edit/{1}.{2}"} + ) + ) + # load extra services specified by users before default handlers for service in self.settings['extra_services']: handlers.extend(load_handlers(service)) From 84b7d2df547f99d70db25ea1ccd62723e7441315 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Mon, 22 Feb 2021 14:16:53 +0100 Subject: [PATCH 2/4] Bump to jupyter_server~=1.4 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3beb13a81..53871840b 100644 --- a/setup.py +++ b/setup.py @@ -55,7 +55,7 @@ python_requires='>=3.6', include_package_data=True, install_requires = [ - 'jupyter_server~=1.1', + 'jupyter_server~=1.4', 'notebook<7', ], entry_points = { From 0ac67f970c00f75fef34a2b6c20e36609c0e99fe Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Tue, 23 Feb 2021 15:18:27 +0100 Subject: [PATCH 3/4] Update regex to handle files without an extension --- nbclassic/notebookapp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nbclassic/notebookapp.py b/nbclassic/notebookapp.py index b801716ad..3e8bf4480 100644 --- a/nbclassic/notebookapp.py +++ b/nbclassic/notebookapp.py @@ -224,9 +224,9 @@ def initialize_handlers(self): # for opening non-ipynb files in edit mode. handlers.append( ( - rf"/({self.file_url_prefix})/(.*)\.(((?!ipynb)).*)", + rf"/{self.file_url_prefix}/((?!.*\.ipynb($|\?)).*)", RedirectHandler, - {"url": "/edit/{1}.{2}"} + {"url": "/edit/{0}"} ) ) From fe3555e96c84e55121b8b4fd58a630d3504e0207 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Tue, 2 Mar 2021 17:58:18 +0100 Subject: [PATCH 4/4] Default subcommands to {} for nbclassic --- nbclassic/notebookapp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nbclassic/notebookapp.py b/nbclassic/notebookapp.py index 3e8bf4480..5985a5763 100644 --- a/nbclassic/notebookapp.py +++ b/nbclassic/notebookapp.py @@ -127,6 +127,7 @@ class NotebookApp( aliases = aliases flags = flags extension_url = "/tree" + subcommands = {} # Override the default open_Browser trait in ExtensionApp, # setting it to True.