Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Toc2] Scrolling: update a mark in TOC to currently displayed section #1057

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ed4bda0
[codefolding] fix restoration of nested folds
jcb91 Aug 16, 2017
1f4d660
Add sticky notification option to notify plugin.
brenns10 Aug 19, 2017
654c45d
Update yaml files for 5.x compatible nbextensions
jfbercher Aug 20, 2017
3a9aa65
Update yaml files for 5.x compatible nbextensions (2)
jfbercher Aug 20, 2017
2df0d64
Update yaml files for skill and splitcell
jfbercher Aug 21, 2017
27fe043
[toc2] Define colors in css. Alterable from config but useful or html…
jfbercher Aug 21, 2017
97e0eb3
[toc2] Reworked (simplified) configuration loading + linting
jfbercher Aug 21, 2017
a1acb44
[toc2] Scrolling: add a mark to currently displayed section in TOC wi…
jfbercher Aug 21, 2017
c200197
Merge pull request #1050 from jcb91/codefolding
juhasch Aug 22, 2017
7a667e4
Fix codefolding preprocessor configuration
Aug 22, 2017
5a94915
Update test with new config option
Aug 22, 2017
80ed43d
Skip preprocessor if not enabled
Aug 22, 2017
fe90a66
Remove redundant check
Aug 22, 2017
4b37d26
Use IPython config object rather than loading our own.
Aug 22, 2017
13f88a0
Add support for sound in notify plugin.
Aug 22, 2017
3a10efa
Renaming and url fixes within notify extension.
Aug 22, 2017
37e1099
[toc2] use amd structure to avoid polluting the global namespace
jcb91 Jul 23, 2017
fe69131
[toc2] move addSaveAsWithToc definition into main.js
jcb91 Aug 15, 2017
7e2baf7
[toc2] add backwards-compatibility for html exported with old version…
jcb91 Aug 16, 2017
a631fa3
[toc2] add extra check for cfg.cell_toc
jcb91 Aug 16, 2017
2eb8186
[toc2] simplify config loading
jcb91 Aug 23, 2017
3a497b0
Merge pull request #1055 from jfbercher/update_yaml
jcb91 Aug 23, 2017
cde7bd6
Implement notification sounds using HTMLAudioElement
brenns10 Aug 23, 2017
42c28ac
Update notify documentation.
brenns10 Aug 23, 2017
3b74c45
Merge pull request #1053 from brenns10/master
jcb91 Aug 23, 2017
5c26d92
[collapsible_headings] bugfix for exporter
jcb91 Jul 24, 2017
4c4e4c6
Merge pull request #1032 from jcb91/tttoc
jcb91 Aug 23, 2017
f9f45e0
Merge pull request #1058 from juhasch/fix/cf_preprocessor
jcb91 Aug 23, 2017
2b747bc
[various] use Jupyter.notebook.config instance, where appropriate
jcb91 Aug 22, 2017
9c31bf3
Merge pull request #1060 from jcb91/collapsible_headings
jcb91 Aug 23, 2017
477bca6
Add note about native drag&drop support
Aug 24, 2017
0421874
[toc2] tentative fix for #1065 -- update jqueryui cdn and version
jfbercher Aug 25, 2017
2d395d3
Merge pull request #1066 from jfbercher/master
jcb91 Aug 25, 2017
459d28b
Merge pull request #1063 from juhasch/doc/dragdrop
juhasch Aug 25, 2017
7654a48
Merge pull request #1061 from jcb91/config
jcb91 Aug 26, 2017
cfa0f7b
[toc2] Updated PR #1057 to toc2.js module version
jfbercher Aug 28, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ class ExporterCollapsibleHeadings(ExporterInliner):
jupyter nbconvert --to html_ch FILE.ipynb
"""

def _template_file_default(self):
return 'collapsible_headings'

def __init__(self, *args, **kwargs):
super(ExporterCollapsibleHeadings, self).__init__(*args, **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,33 @@
"""

from nbconvert.preprocessors import Preprocessor
from traitlets import Bool, Unicode


class CodeFoldingPreprocessor(Preprocessor):
"""
:mod:`nbconvert` Preprocessor for the code_folding nbextension.

Folds codecells as displayed in the notebook.
Folds codecells as displayed in the notebook. The hidden code below the fold gets removed.

The preprocessor is installed by default. To enable codefolding with
NbConvert, you need to set the configuration parameter
`NbConvertApp.codefolding=True`.
`CodeFoldingPreprocessor.remove_folded_code=True`.
This can be done either in the `jupyter_nbconvert_config.py` file::

c.NbConvertApp.codefolding = True
c.CodeFoldingPreprocessor.remove_folded_code=True = True

or using a command line parameter when calling NbConvert::

$ jupyter nbconvert --to html --NbConvertApp.codefolding=True mynotebook.ipynb
$ jupyter nbconvert --to html --CodeFoldingPreprocessor.remove_folded_code=True mynotebook.ipynb

The folding mark can be configured using
c.CodeFoldingPreprocessor.fold_mark = '<->'

""" # noqa: E501

fold_mark = u'↔'
remove_folded_code = Bool(False, help="Remove code that was folded").tag(config=True)
fold_mark = Unicode(u'↔', help="Symbol for folded code").tag(config=True)

def fold_cell(self, cell, folded):
"""
Expand Down Expand Up @@ -54,10 +59,16 @@ def fold_cell(self, cell, folded):
fcell += l
return fcell

def preprocess(self, nb, resources):
"""Skip preprocessor if not enabled"""
if self.remove_folded_code:
return super(CodeFoldingPreprocessor, self).preprocess(nb, resources)
else:
return nb, resources

def preprocess_cell(self, cell, resources, index):
"""
Read cell metadata and remove lines marked as `folded`.
Requires configuration parameter 'NbConvertApp.codefolding = True'

Parameters
----------
Expand All @@ -69,10 +80,10 @@ def preprocess_cell(self, cell, resources, index):
index : int
Index of the cell being processed (see base.py)
"""
dofolding = self.config.NbConvertApp.get('codefolding', False) is True
if hasattr(cell, 'source') and cell.cell_type == 'code' and dofolding:
if hasattr(cell, 'source') and cell.cell_type == 'code':
if hasattr(cell['metadata'], 'code_folding'):
folded = cell['metadata']['code_folding']
if len(folded) > 0:
self.log.debug('Removing folded code in cell')
cell.source = self.fold_cell(cell.source, folded)
return cell, resources
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Type: IPython Notebook Extension
Compatibility: 3.x, 4.x
Compatibility: 3.x, 4.x, 5.x
Name: AutoSaveTime
Main: main.js
Icon: icon.png
Expand Down
19 changes: 6 additions & 13 deletions src/jupyter_contrib_nbextensions/nbextensions/autosavetime/main.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
define([
'jquery',
'base/js/namespace',
'base/js/events',
'base/js/utils',
'services/config'
'base/js/events'
], function(
$,
IPython,
events,
utils,
configmod
events
) {
"use strict";

// create config object to load parameters
var base_url = utils.get_body_data("baseUrl");
var config = new configmod.ConfigSection('notebook', {base_url: base_url});

// define default values for config parameters
var params = {
autosavetime_set_starting_interval : false,
Expand All @@ -26,13 +18,14 @@ define([

// update params with any specified in the server's config file
var update_params = function() {
var config = IPython.notebook.config;
for (var key in params) {
if (config.data.hasOwnProperty(key))
params[key] = config.data[key];
}
};

config.loaded.then( function() {
var initialize = function () {
update_params();

var si = params.autosavetime_starting_interval;
Expand Down Expand Up @@ -76,10 +69,10 @@ define([
}
}
});
});
};

var load_ipython_extension = function() {
config.load();
return IPython.notebook.config.loaded.then(initialize);
};

return {
Expand Down
22 changes: 9 additions & 13 deletions src/jupyter_contrib_nbextensions/nbextensions/autoscroll/main.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
define([
'jquery',
'base/js/namespace',
'base/js/utils',
'services/config',
'base/js/events',
'notebook/js/outputarea',
'notebook/js/codecell'
], function (
$,
IPython,
utils,
configmod,
oa, codecell
events,
oa,
codecell
) {
"use strict";

Expand All @@ -25,12 +24,9 @@ define([
autoscroll_show_button : false
};

// create config object to load parameters
var base_url = utils.get_body_data("baseUrl");
var config = new configmod.ConfigSection('notebook', {base_url: base_url});

// update params with any specified in the server's config file
var update_params = function() {
var config = IPython.notebook.config;
for (var key in params) {
if (config.data.hasOwnProperty(key))
params[key] = config.data[key];
Expand Down Expand Up @@ -69,7 +65,7 @@ define([
initAutoScroll();
};

config.loaded.then( function() {
var initialize = function() {
update_params();

var thresholds = [-1, 1, 10, 20, 50, 100, 200, 500, 1000];
Expand Down Expand Up @@ -107,7 +103,7 @@ define([
IPython.toolbar.add_buttons_group([action_full_name]);
}
initAutoScroll();
});
};

var load_ipython_extension = function () {
var prefix = 'auto';
Expand All @@ -121,8 +117,8 @@ define([

action_full_name = IPython.keyboard_manager.actions.register(action, action_name, prefix);

config.load();
$([IPython.events]).on("notebook_loaded.Notebook", function(){
IPython.notebook.config.loaded.then(initialize);
events.on("notebook_loaded.Notebook", function(){
initAutoScroll();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
// works with images and notebook cells (MIME-type 'notebook-cell/json')

define([
'base/js/namespace',
'jquery',
'base/js/utils',
'services/config',
'base/js/namespace',
'base/js/events'
], function(IPython, $, utils, configmod, events) {
], function(
$,
IPython,
events
) {
"use strict";
if (window.chrome === undefined) return;

var params = {
subdirectory : '',
};

var base_url = utils.get_body_data("baseUrl");
var config = new configmod.ConfigSection('notebook', {base_url: base_url});

/* http://stackoverflow.com/questions/3231459/create-unique-id-with-javascript */
function uniqueid(){
// always start with a letter (for DOM friendlyness)
Expand Down Expand Up @@ -58,7 +57,7 @@ define([
name = uniqueid() + '.' + msg.match(/data:image\/(\S+);/)[1];
}
create_dir(path);
var url = '//' + location.host + utils.url_path_join(base_url, 'api/contents', path, name);
var url = '//' + location.host + utils.url_path_join(IPython.notebook.base_url, 'api/contents', path, name);

var img = msg.replace(/(^\S+,)/, ''); // strip header
//console.log("send_to_server:", url, img);
Expand Down Expand Up @@ -90,10 +89,9 @@ define([
*/
var load_ipython_extension = function() {

config.load();
config.loaded
IPython.notebook.config.loaded
.then(function () {
$.extend(true, params, config.data.dragdrop); // update params
$.extend(true, params, IPython.notebook.config.data.dragdrop); // update params
if (params.subdirectory) {
console.log('subdir:', params.subdirectory)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Link: README.md
Description: Adds toolbar buttons to increase and decrease code's font size.
This is useful, for example, when projecting the notebook.
Main: code_font_size.js
Compatibility: 4.x
Compatibility: 4.x, 5.x
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ define(function(require, exports, module) {
var $ = require('jquery');
var Jupyter = require('base/js/namespace');
var events = require('base/js/events');
var utils = require('base/js/utils');
var ConfigSection = require('services/config').ConfigSection;
var CodeCell = require('notebook/js/codecell').CodeCell;

// this wrapper function allows config & hotkeys to be per-plugin
Expand Down Expand Up @@ -286,13 +284,11 @@ define(function(require, exports, module) {

KernelExecOnCells.prototype.initialize_plugin = function() {
var that = this;
var base_url = utils.get_body_data("baseUrl");
var conf_section = new ConfigSection('notebook', { base_url: base_url });
// first, load config
conf_section.load()
Jupyter.notebook.config.loaded
// now update default config with that loaded from server
.then(function on_success(config_data) {
$.extend(true, that.cfg, config_data[that.mod_name]);
.then(function on_success() {
$.extend(true, that.cfg, Jupyter.notebook.config.data[that.mod_name]);
}, function on_error(err) {
console.warn(that.mod_log_prefix, 'error loading config:', err);
})
Expand Down
43 changes: 29 additions & 14 deletions src/jupyter_contrib_nbextensions/nbextensions/codefolding/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,31 @@ define([
cm.setOption('foldGutter', opts);
}

/**
* Restore folding status from metadata
* @param cell
*/
var restoreFolding = function (cell) {
if (cell.metadata.code_folding === undefined || !(cell instanceof codecell.CodeCell)) {
return;
}
// visit in reverse order, as otherwise nested folds un-fold outer ones
var lines = cell.metadata.code_folding.slice().sort();
for (var idx = lines.length - 1; idx >= 0; idx--) {
var line = lines[idx];
var opts = cell.code_mirror.state.foldGutter.options;
var linetext = cell.code_mirror.getLine(line);
if (linetext !== undefined) {
cell.code_mirror.foldCode(CodeMirror.Pos(line, 0), opts.rangeFinder);
}
else {
// the line doesn't exist, so we should remove it from metadata
cell.metadata.code_folding = lines.slice(0, idx);
}
cell.code_mirror.refresh();
}
};

/**
* Add codefolding gutter to a new cell
*
Expand All @@ -160,6 +185,9 @@ define([
activate_cm_folding(cell.code_mirror);
cell.code_mirror.on('fold', updateMetadata);
cell.code_mirror.on('unfold', updateMetadata);
// queue restoring folding, to run once metadata is set, hopefully.
// This can be useful if cells are un-deleted, for example.
setTimeout(function () { restoreFolding(cell); }, 500);
}
};

Expand All @@ -175,20 +203,7 @@ define([
if ((cell instanceof codecell.CodeCell)) {
activate_cm_folding(cell.code_mirror);
/* restore folding state if previously saved */
if (cell.metadata.code_folding !== undefined) {
for (var idx = 0; idx < cell.metadata.code_folding.length; idx++) {
var line = cell.metadata.code_folding[idx];
var opts = cell.code_mirror.state.foldGutter.options;
var linetext = cell.code_mirror.getLine(line);
if (linetext !== undefined) {
cell.code_mirror.foldCode(CodeMirror.Pos(line, 0), opts.rangeFinder);
} else {
cell.metadata.code_folding = [];
break;
}
cell.code_mirror.refresh();
}
}
restoreFolding(cell);
cell.code_mirror.on('fold', updateMetadata);
cell.code_mirror.on('unfold', updateMetadata);
}
Expand Down
Loading