Skip to content

Commit

Permalink
Add the Quarto format to the Jupyter Notebook & Jupyter Lab extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Sep 4, 2021
1 parent 0e9c47c commit ddbd53a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 6 additions & 4 deletions jupytext/nbextension/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ define([
}

var notebook_extension = Jupyter.notebook.notebook_path.split('.').pop();
notebook_extension = ['ipynb', 'md', 'Rmd'].indexOf(notebook_extension) == -1 ? 'auto' : notebook_extension;
notebook_extension = ['ipynb', 'md', 'Rmd', 'qmd'].indexOf(notebook_extension) == -1 ? 'auto' : notebook_extension;
for (var i in formats) {
var ext = formats[i].split(':')[0];
if (ext == notebook_extension)
return formats;
}

// the notebook extension was not found among the formats
if (['ipynb', 'md', 'Rmd'].indexOf(notebook_extension) != -1)
if (['ipynb', 'md', 'Rmd', 'qmd'].indexOf(notebook_extension) != -1)
formats.push(notebook_extension);
else {
var format_name = Jupyter.notebook.metadata.jupytext && Jupyter.notebook.metadata.jupytext.text_representation
Expand All @@ -70,7 +70,7 @@ define([
$('#jupytext_pair_' + fmt.replace(':', '_') + ' > .fa').toggleClass('fa-check', true);

// any custom format?
if (['ipynb', 'auto:light', 'auto:percent', 'auto:hydrogen', 'auto:nomarker', 'md', 'Rmd', 'md:myst'].indexOf(fmt) == -1)
if (['ipynb', 'auto:light', 'auto:percent', 'auto:hydrogen', 'auto:nomarker', 'md', 'Rmd', 'qmd', 'md:myst'].indexOf(fmt) == -1)
$('#jupytext_pair_custom' + ' > .fa').toggleClass('fa-check', true);
}

Expand Down Expand Up @@ -112,7 +112,7 @@ define([
}
var formats = getSelectedJupytextFormats();
var notebook_extension = Jupyter.notebook.notebook_path.split('.').pop();
notebook_extension = ['ipynb', 'md', 'Rmd'].indexOf(notebook_extension) == -1 ? 'auto' : notebook_extension;
notebook_extension = ['ipynb', 'md', 'Rmd', 'qmd'].indexOf(notebook_extension) == -1 ? 'auto' : notebook_extension;

// Toggle the selected format
var index = formats.indexOf(format);
Expand Down Expand Up @@ -380,6 +380,7 @@ define([
TextNotebooks.append(text_notebook_entry('MyST Markdown', '.md:myst'));
TextNotebooks.append($('<li/>').addClass('divider'));
TextNotebooks.append(text_notebook_entry('R Markdown', '.Rmd'));
TextNotebooks.append(text_notebook_entry('Quarto', '.qmd'));

// Jupytext menu
$('#open_notebook').before('<li id="jupytext_sub_menu"/>');
Expand All @@ -400,6 +401,7 @@ define([
JupytextActions.append(jupytext_pair('md', 'Pair Notebook with Markdown'));
JupytextActions.append(jupytext_pair('md:myst', 'Pair Notebook with MyST Markdown'));
JupytextActions.append(jupytext_pair('Rmd', 'Pair Notebook with R Markdown', notebook_extension !== 'Rmd'));
JupytextActions.append(jupytext_pair('qmd', 'Pair Notebook with Quarto (qmd)', notebook_extension !== 'qmd'));
JupytextActions.append(jupytext_pair('custom', 'Custom pairing'));
JupytextActions.append($('<li/>').addClass('divider'));
JupytextActions.append(toggle_metadata);
Expand Down
4 changes: 4 additions & 0 deletions packages/labextension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.3.5 (2021-09-05)

- The extension can pair notebooks with `.qmd` files (Quarto format) (#837)

# 1.3.4 (2021-08-31)

- We have upgraded the extension dependencies and especially `tar` and `url-parse` to fix two security vulnerabilities (#842) (#843)
Expand Down
12 changes: 8 additions & 4 deletions packages/labextension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ const JUPYTEXT_FORMATS = [
format: "Rmd",
label: "Pair Notebook with R Markdown"
},
{
format: "qmd",
label: "Pair Notebook with Quarto (qmd)"
},
{
format: "custom",
label: "Custom pairing"
Expand Down Expand Up @@ -97,15 +101,15 @@ function get_selected_formats(notebook_tracker: INotebookTracker): Array<string>
if (!notebook_extension)
return formats;

notebook_extension = ['ipynb', 'md', 'Rmd'].indexOf(notebook_extension) == -1 ? 'auto' : notebook_extension;
notebook_extension = ['ipynb', 'md', 'Rmd', 'qmd'].indexOf(notebook_extension) == -1 ? 'auto' : notebook_extension;
for (const i in formats) {
const ext = formats[i].split(':')[0];
if (ext == notebook_extension)
return formats;
}

// the notebook extension was not found among the formats
if (['ipynb', 'md', 'Rmd'].indexOf(notebook_extension) != -1)
if (['ipynb', 'md', 'Rmd', 'qmd'].indexOf(notebook_extension) != -1)
formats.push(notebook_extension);
else {
let format_name = 'light';
Expand Down Expand Up @@ -149,7 +153,7 @@ const extension: JupyterFrontEndPlugin<void> = {
if (format == "custom"){
for (const i in jupytext_formats) {
const fmt = jupytext_formats[i];
if (['ipynb', 'auto:light', 'auto:percent', 'auto:hydrogen', 'auto:nomarker', 'md', 'Rmd', 'md:myst'].indexOf(fmt)==-1)
if (['ipynb', 'auto:light', 'auto:percent', 'auto:hydrogen', 'auto:nomarker', 'md', 'Rmd', 'qmd', 'md:myst'].indexOf(fmt)==-1)
return true;
}
return false;
Expand Down Expand Up @@ -187,7 +191,7 @@ const extension: JupyterFrontEndPlugin<void> = {
}
// Toggle the selected format
let notebook_extension: string = notebook_tracker.currentWidget.context.path.split('.').pop();
notebook_extension = ['ipynb', 'md', 'Rmd'].indexOf(notebook_extension) == -1 ? 'auto' : notebook_extension;
notebook_extension = ['ipynb', 'md', 'Rmd', 'qmd'].indexOf(notebook_extension) == -1 ? 'auto' : notebook_extension;

// Toggle the selected format
const index = formats.indexOf(format);
Expand Down

0 comments on commit ddbd53a

Please sign in to comment.