Skip to content

Commit

Permalink
[ruler] css patch for notebook > 4.2.3
Browse files Browse the repository at this point in the history
see jupyter/notebook#2869 for details
  • Loading branch information
jcb91 committed Sep 30, 2017
1 parent 862c6b3 commit de1ad62
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/jupyter_contrib_nbextensions/nbextensions/ruler/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ define([
var ruler_column = [78];
var ruler_color = ["#ff0000"];
var ruler_linestyle = ["dashed"];
var ruler_do_css_patch;

var rulers = [];

Expand Down Expand Up @@ -51,6 +52,8 @@ define([
});
}
console.debug(log_prefix, 'ruler specs:', rulers);

ruler_do_css_patch = config.data.ruler_do_css_patch; // undefined is ok
}

var load_ipython_extension = function() {
Expand All @@ -59,13 +62,29 @@ define([
console.warn(log_prefix, 'error loading config:', reason);
})
.then(function () {
// Add css patch fix for notebook > 4.2.3 - see
// https://github.com/jupyter/notebook/issues/2869
// for details
if (ruler_do_css_patch !== false) {
var sheet = document.createElement('style');
sheet.innerHTML = [
'.CodeMirror-lines {',
' padding: 0.4em 0; /* Vertical padding around content */',
'}',
'.CodeMirror pre {',
' padding: 0 0.4em; /* Horizonal padding around content */',
'}',
].join('\n');
document.head.appendChild(sheet);
}

// Change default for new cells
codecell.CodeCell.options_default.cm_config.rulers = rulers;
// Apply to any already-existing cells
var cells = Jupyter.notebook.get_cells().forEach(function (cell) {
if (cell instanceof codecell.CodeCell) {
cell.code_mirror.setOption('rulers', rulers);
}
}
});
})
.catch(function on_error (reason) {
Expand Down
16 changes: 15 additions & 1 deletion src/jupyter_contrib_nbextensions/nbextensions/ruler/readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Ruler
=====

This extension enables the Ruler CodeMirror feature


Expand All @@ -15,8 +16,21 @@ cm = ConfigManager(parent=ip)
cm.update('notebook', {"ruler_column": [80]})
```


#### CSS patch ####

Notebook versions from 4.3.0 through 5.1.0dev show up a bug in their CodeMirror
CSS padding which causes the ruler to be misplaced (see
[jupyter/notebook#2869](https://github.com/jupyter/notebook/issues/2869)
for details).
This nbextension introduces a css patch to attempt to correct this, but if it
causes problems for you, you can disable it by setting the `ruler_do_css_patch`
config key to `false`.


#### Multiple Rulers ####
To specify multiple rulers, set the `ruler_column` to an list of values, for example

To specify multiple rulers, set the `ruler_column` to a list of values, for example

```Python
cm.update('notebook', {"ruler_column": [10, 20, 30, 40, 50, 60, 70, 80]})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@ Icon: icon.png
Main: main.js
Compatibility: 4.x, 5.x
Parameters:

- name: ruler_column
input_type: list
list_element:
input_type: number
description: Column where ruler is displayed
default: [78]

- name: ruler_color
input_type: list
list_element:
input_type: color
description: Ruler color
default: ["#ff0000"]

- name: ruler_linestyle
description: 'Ruler style, e.g. solid, dashed'
input_type: list
default: ['dashed']

- name: ruler_do_css_patch
description: apply css patch for ruler padding bug in notebook >= 4.3
input_type: checkbox
default: true

0 comments on commit de1ad62

Please sign in to comment.