Skip to content

Commit

Permalink
Reformat in VS Code
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Jun 1, 2020
1 parent 4832859 commit d8f7b32
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions jupytext/nbextension/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ define([
var formats = [];
for (var i in unfiltered_formats) {
var fmt = unfiltered_formats[i];
if(fmt)
if (fmt)
formats.push(fmt);
}

Expand All @@ -43,16 +43,16 @@ define([
notebook_extension = ['ipynb', 'md', 'Rmd'].indexOf(notebook_extension) == -1 ? 'auto' : notebook_extension;
for (var i in formats) {
var ext = formats[i].split(':')[0];
if (ext==notebook_extension)
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'].indexOf(notebook_extension) != -1)
formats.push(notebook_extension);
else {
var format_name = Jupyter.notebook.metadata.jupytext && Jupyter.notebook.metadata.jupytext.text_representation
&& Jupyter.notebook.metadata.jupytext.text_representation.format_name ?
&& Jupyter.notebook.metadata.jupytext.text_representation.format_name ?
Jupyter.notebook.metadata.jupytext.text_representation.format_name : 'light';
formats.push('auto:' + format_name);
}
Expand All @@ -70,12 +70,12 @@ 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', 'md:myst'].indexOf(fmt) == -1)
$('#jupytext_pair_custom' + ' > .fa').toggleClass('fa-check', true);
}

// just one format?
if (formats.length===1)
if (formats.length === 1)
$('#jupytext_pair_none').parent().addClass('disabled');
else
$('#jupytext_pair_none').parent().removeClass('disabled');
Expand Down Expand Up @@ -116,25 +116,25 @@ define([

// Toggle the selected format
var index = formats.indexOf(format);
if (format==='none') {
if (format === 'none') {
// Only keep one format - one that matches the current extension
for(var i in formats) {
for (var i in formats) {
var fmt = formats[i];
if(fmt.split(':')[0] === notebook_extension) {
if (fmt.split(':')[0] === notebook_extension) {
formats = [fmt];
break;
}
}
}
else if(index!=-1) {
else if (index != -1) {
formats.splice(index, 1);

// The current file extension can't be unpaired
var ext_found = false;
for(var i in formats) {
for (var i in formats) {
var fmt = formats[i];
if(fmt.split(':')[0] === notebook_extension) {
ext_found=true;
if (fmt.split(':')[0] === notebook_extension) {
ext_found = true;
break;
}
}
Expand All @@ -144,9 +144,9 @@ define([
} else {
// We can't have the same extension multiple times
var new_formats = [];
for(var i in formats) {
for (var i in formats) {
var fmt = formats[i];
if(fmt.split(':')[0] !== format.split(':')[0]) {
if (fmt.split(':')[0] !== format.split(':')[0]) {
new_formats.push(fmt)
}
}
Expand All @@ -158,8 +158,7 @@ define([
if (formats.length === 1) {
if (notebook_extension !== 'auto')
formats = [];
else
{
else {
if (Jupyter.notebook.metadata.jupytext && Jupyter.notebook.metadata.jupytext.text_representation) {
var format_name = formats[0].split(':')[1];
Jupyter.notebook.metadata.jupytext.text_representation.format_name = format_name;
Expand Down Expand Up @@ -235,7 +234,7 @@ define([
);
}

function new_text_notebook(ext='.md') {
function new_text_notebook(ext = '.md') {
// Differences with KernelSelector.prototype.new_notebook from
// https://github.com/jupyter/notebook/blob/
// 6e9256b0641a85baf664e846515085bac2c082a3/notebook/static/notebook/js/kernelselector.js
Expand All @@ -247,7 +246,7 @@ define([
// Create a new notebook in the same path as the current
// notebook's path.
var parent = utils.url_path_split(Jupyter.notebook.notebook_path)[0];
Jupyter.notebook.contents.new_untitled(parent, {type: "notebook", ext:ext}).then(
Jupyter.notebook.contents.new_untitled(parent, { type: "notebook", ext: ext }).then(
function (data) {
var url = utils.url_path_join(
Jupyter.notebook.base_url, 'notebooks',
Expand All @@ -256,12 +255,12 @@ define([
url += "?kernel_name=" + Jupyter.notebook.metadata.kernelspec.name;
w.location = url;
},
function(error) {
function (error) {
w.close();
dialog.modal({
title : i18n.msg._('Creating Notebook Failed'),
body : i18n.msg.sprintf(i18n.msg._("The error was: %s"), error.message),
buttons : {'OK' : {'class' : 'btn-primary'}}
title: i18n.msg._('Creating Notebook Failed'),
body: i18n.msg.sprintf(i18n.msg._("The error was: %s"), error.message),
buttons: { 'OK': { 'class': 'btn-primary' } }
});
}
);
Expand Down Expand Up @@ -393,14 +392,14 @@ define([
JupytextActions.append($('<li/>').addClass('divider'));

var notebook_extension = Jupyter.notebook.notebook_path.split('.').pop();
JupytextActions.append(jupytext_pair('ipynb', 'Pair Notebook with ipynb document', notebook_extension!=='ipynb'));
JupytextActions.append(jupytext_pair('ipynb', 'Pair Notebook with ipynb document', notebook_extension !== 'ipynb'));
JupytextActions.append(jupytext_pair('auto:light', 'Pair Notebook with light Script'));
JupytextActions.append(jupytext_pair('auto:percent', 'Pair Notebook with percent Script'));
JupytextActions.append(jupytext_pair('auto:hydrogen', 'Pair Notebook with Hydrogen Script'));
JupytextActions.append(jupytext_pair('auto:nomarker', 'Pair Notebook with nomarker Script'));
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('Rmd', 'Pair Notebook with R Markdown', notebook_extension !== 'Rmd'));
JupytextActions.append(jupytext_pair('custom', 'Custom pairing'));
JupytextActions.append($('<li/>').addClass('divider'));
JupytextActions.append(toggle_metadata);
Expand Down

0 comments on commit d8f7b32

Please sign in to comment.