Skip to content

Commit

Permalink
more robust way to compute the JLAB4 flag
Browse files Browse the repository at this point in the history
checks that app.name is JupyterLab before setting JLAB4 = false
this way if a future app has version 1.x, it will not trigger the jlab3 code
  • Loading branch information
parmentelat committed Jun 29, 2023
1 parent 2164f46 commit 5e2f412
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ function getJupytextFormats(trans: TranslationBundle): IJupytextFormat[] {
const LANGUAGE_INDEPENDENT_NOTEBOOK_EXTENSIONS = ["ipynb", "md", "Rmd", "qmd"];

// will get updated upon activation
// default is true, and we will turn this off only iff
// app.name is "JupyterLab" and the version is 3.x or below
let JLAB4 = true;

function get_jupytext_formats(notebook_tracker: INotebookTracker): Array<string> {
Expand Down Expand Up @@ -215,12 +217,13 @@ const extension: JupyterFrontEndPlugin<void> = {
// https://semver.org/#semantic-versioning-specification-semver
// npm semver requires pre-release versions to come with a hyphen
// so 7.0.0rc2 won't work with semver
// in addition, when running in the notebook7 context, app.version
// returns the notebook's version, not jupyterlab !
// ignoring the second point for now (it accidentally works...)
const app_numbers = app.version.match(/[0-9]+/)
if (app_numbers) {
JLAB4 = parseInt(app_numbers[0]) >= 4;
// in addition, when running in the notebook7 context, app refers
// to the notebook7 application, not the jupyterlab application
if (app.name == "JupyterLab") {
const app_numbers = app.version.match(/[0-9]+/);
if (app_numbers) {
JLAB4 = parseInt(app_numbers[0]) >= 4;
}
}
console.log("JupyterLab extension jupyterlab-jupytext is activated!");
console.debug(`JLAB4=${JLAB4}`);
Expand Down

0 comments on commit 5e2f412

Please sign in to comment.