mirror of
https://github.com/wassname/jupyter_contrib_nbextensions.git
synced 2026-09-11 12:20:19 +08:00
Update ruler extension
This commit is contained in:
@@ -7,38 +7,58 @@ define([
|
||||
'require',
|
||||
'base/js/events',
|
||||
'services/config',
|
||||
'base/js/utils',
|
||||
'base/js/utils',
|
||||
'codemirror/lib/codemirror',
|
||||
'codemirror/addon/display/rulers'
|
||||
], function(IPython, $, require, events, configmod, utils, codemirror) {
|
||||
"use strict";
|
||||
|
||||
var RULERCOLUMN = 78;
|
||||
var base_url = utils.get_body_data("baseUrl")
|
||||
var ruler_column = 78;
|
||||
var ruler_color = "#ff0000";
|
||||
var ruler_linestyle = "dashed";
|
||||
|
||||
var base_url = utils.get_body_data("baseUrl");
|
||||
var config = new configmod.ConfigSection('notebook', {base_url: base_url});
|
||||
var rulers = [];
|
||||
|
||||
function isNumber(n) {
|
||||
var isNumber = function(n) {
|
||||
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||
}
|
||||
};
|
||||
|
||||
config.loaded.then(function() {
|
||||
if (config.data.hasOwnProperty('ruler_column') ){
|
||||
if (isNumber(config.data.ruler_column)) RULERCOLUMN = config.data.ruler_column;
|
||||
if (config.data.hasOwnProperty('ruler_color')) {
|
||||
ruler_color = config.data.ruler_color;
|
||||
}
|
||||
console.log("RULER:", RULERCOLUMN)
|
||||
rulers.push({color: "#f00", column: RULERCOLUMN, lineStyle: "dashed"});
|
||||
console.log("ruler_color:", ruler_color);
|
||||
|
||||
if (config.data.hasOwnProperty('ruler_column')) {
|
||||
if (isNumber(config.data.ruler_column)) {
|
||||
ruler_column = config.data.ruler_column;
|
||||
}
|
||||
}
|
||||
console.log("ruler_column:", ruler_column);
|
||||
|
||||
if (config.data.hasOwnProperty('ruler_linestyle')) {
|
||||
ruler_linestyle = config.data.ruler_linestyle;
|
||||
}
|
||||
console.log("ruler_linestyle:", ruler_linestyle);
|
||||
|
||||
rulers.push({
|
||||
color: ruler_color,
|
||||
column: ruler_column,
|
||||
lineStyle: ruler_linestyle
|
||||
});
|
||||
var cells = IPython.notebook.get_cells();
|
||||
for(var i in cells){
|
||||
for(var i in cells) {
|
||||
var cell = cells[i];
|
||||
if ((cell instanceof IPython.CodeCell)) {
|
||||
cell.code_mirror.setOption('rulers', rulers);
|
||||
}
|
||||
}
|
||||
events.on('create.Cell',createCell);
|
||||
events.on('create.Cell', createCell);
|
||||
});
|
||||
|
||||
var createCell = function (event,nbcell) {
|
||||
var createCell = function (event, nbcell) {
|
||||
var cell = nbcell.cell;
|
||||
if ((cell instanceof IPython.CodeCell)) {
|
||||
cell.code_mirror.setOption('rulers', rulers);
|
||||
|
||||
@@ -1 +1,11 @@
|
||||
Display a rulter
|
||||
This extension enables the Ruler CodeMirror feature
|
||||
|
||||
## Configuration
|
||||
|
||||
You can set the number of characters in the notebook extensions configration page or use the ConfigManager:
|
||||
```Python
|
||||
from IPython.html.services.config import ConfigManager
|
||||
ip = get_ipython()
|
||||
cm = ConfigManager(parent=ip)
|
||||
cm.update('notebook', {"ruler_column": 80})
|
||||
```
|
||||
|
||||
@@ -10,3 +10,10 @@ Parameters:
|
||||
input_type: number
|
||||
description: Column where ruler is displayed
|
||||
default: 78
|
||||
ruler_color:
|
||||
input_type: color
|
||||
description: Color of the ruler
|
||||
default: "#ff0000"
|
||||
ruler_linestyle:
|
||||
description: 'Ruler style, e.g. solid, dashed'
|
||||
default: dashed
|
||||
|
||||
Reference in New Issue
Block a user