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

[ruler] css patch for notebook > 4.2.3 #1116

Merged
merged 1 commit into from
Oct 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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