From f77adcd222563b1a02b91beb190d9167b791b6ae Mon Sep 17 00:00:00 2001 From: MinRK Date: Sun, 29 Sep 2013 20:10:40 -0700 Subject: [PATCH 01/13] add raw_format to Exporter classes sets their values in resources --- IPython/nbconvert/exporters/python.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/IPython/nbconvert/exporters/python.py b/IPython/nbconvert/exporters/python.py index a3b475155..0eed52578 100644 --- a/IPython/nbconvert/exporters/python.py +++ b/IPython/nbconvert/exporters/python.py @@ -1,6 +1,5 @@ -""" -Python exporter which exports Notebook code into a PY file. -""" +"""Python script Exporter class""" + #----------------------------------------------------------------------------- # Copyright (c) 2013, the IPython Development Team. # @@ -29,3 +28,10 @@ class PythonExporter(TemplateExporter): file_extension = Unicode( 'py', config=True, help="Extension of the file that should be written to disk") + + def _raw_format_default(self): + return 'python' + + def _raw_formats_default(self): + return ['py', 'python'] + From 66fe540412aec39d470473e7ea8a46359d3a6d26 Mon Sep 17 00:00:00 2001 From: MinRK Date: Fri, 4 Oct 2013 11:04:39 -0700 Subject: [PATCH 02/13] rename Raw Text to Raw NBConvert in menu --- IPython/html/templates/notebook.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IPython/html/templates/notebook.html b/IPython/html/templates/notebook.html index a23bc1a49..637d1445d 100644 --- a/IPython/html/templates/notebook.html +++ b/IPython/html/templates/notebook.html @@ -157,8 +157,8 @@ class="notebook_app" title="Contents will be rendered as HTML and serve as explanatory text"> Markdown
  • - Raw Text
  • + title="Contents will pass through nbconvert unmodified"> + Raw NBConvert
  • Heading 1
  • Heading 2
  • Heading 3
  • From 549b343a8843808777ebe3b7b13836611d21ec7d Mon Sep 17 00:00:00 2001 From: MinRK Date: Wed, 6 Nov 2013 11:52:30 -0800 Subject: [PATCH 03/13] tweak global hide/show make hierarchical rather than either/or. Also, don't use the same class name for the outer and inner css classes. --- .../html/static/notebook/js/celltoolbar.js | 24 ++++---- .../static/notebook/less/celltoolbar.less | 55 ++++--------------- IPython/html/static/style/style.min.css | 15 ++--- 3 files changed, 27 insertions(+), 67 deletions(-) diff --git a/IPython/html/static/notebook/js/celltoolbar.js b/IPython/html/static/notebook/js/celltoolbar.js index 9c43f0dd3..21ad9ac22 100644 --- a/IPython/html/static/notebook/js/celltoolbar.js +++ b/IPython/html/static/notebook/js/celltoolbar.js @@ -37,37 +37,39 @@ var IPython = (function (IPython) { this.inner_element = $('
    ').addClass('celltoolbar') this.element = $('
    ').addClass('ctb_hideshow') .append(this.inner_element); + this.show(); }; // The default css style for the outer celltoolbar div - // (ctb_hideshow) is display: none. We add the ctb_show - // class to either 1) the body to show all cell's toolbars - // or 2) to the individual celltoolbar divs to show just one - // cell's toolbar. + // (ctb_hideshow) is display: none. + // To show the cell toolbar, *both* of the following conditions must be met: + // - A parent container has class `ctb_global_show` + // - The celltoolbar has the class `ctb_show` + // This allows global show/hide, as well as per-cell show/hide. CellToolbar.global_hide = function () { - $('body').removeClass('ctb_show'); - } + $('body').removeClass('ctb_global_show'); + }; CellToolbar.global_show = function () { - $('body').addClass('ctb_show'); - } + $('body').addClass('ctb_global_show'); + }; CellToolbar.prototype.hide = function () { this.element.removeClass('ctb_show'); - } + }; CellToolbar.prototype.show = function () { this.element.addClass('ctb_show'); - } + }; /** - * Class variable that should contain a dict of all availlable callback + * Class variable that should contain a dict of all available callback * we need to think of wether or not we allow nested namespace * @property _callback_dict * @private diff --git a/IPython/html/static/notebook/less/celltoolbar.less b/IPython/html/static/notebook/less/celltoolbar.less index 4c1ef6b2a..057b40be3 100644 --- a/IPython/html/static/notebook/less/celltoolbar.less +++ b/IPython/html/static/notebook/less/celltoolbar.less @@ -1,12 +1,10 @@ -/* Css for the metadata edit area */ - +/* CSS for the cell toolbar */ .celltoolbar { border: thin solid #CFCFCF; border-bottom: none; background : #EEE; - border-top-right-radius: 3px; - border-top-left-radius: 3px; + border-radius : 3px 3px 0px 0px; width:100%; -webkit-box-pack: end; height:22px; @@ -14,20 +12,6 @@ .reverse(); } - -.no_input_radius { - border-top-right-radius: 0px; - border-top-left-radius: 0px; -} - -.text_cell .ctb_prompt { - display: none; -} - -.code_cell .ctb_prompt { - display: block; -} - .ctb_hideshow { display:none; vertical-align:bottom; @@ -38,41 +22,21 @@ padding-top: 0px; } -.ctb_area { - margin:0; - padding:0; - width:100%; -} - - -/*ctb_show is added to either body or the ctb_hideshow div to show -all or one cell's toolbars. +/* ctb_show is added to the ctb_hideshow div to show the cell toolbar. + Cell toolbars are only shown when the ctb_global_show class is also set. */ -.ctb_show.ctb_hideshow, .ctb_show .ctb_hideshow { - display:block; +.ctb_global_show .ctb_show.ctb_hideshow { + display: block; } -.ctb_show .input_area, -.ctb_show .ctb_hideshow + div.text_cell_input { +.ctb_global_show .ctb_show + .input_area, +.ctb_global_show .ctb_show + div.text_cell_input +{ border-top-right-radius: 0px; border-top-left-radius: 0px; } -.ctb_show > .celltoolbar { - border-bottom-right-radius: 0px; - border-bottom-left-radius: 0px; -} - -.button_container { - margin-top:0; - margin-bottom:0; -} - - -.ui-button { - min-width:30px; -} .celltoolbar .button_container select { margin: 10px; margin-top: 1px; @@ -108,4 +72,5 @@ all or one cell's toolbars. border: none; vertical-align:top; height:20px; + min-width:30px; } diff --git a/IPython/html/static/style/style.min.css b/IPython/html/static/style/style.min.css index 817ba7387..ae9f27b73 100644 --- a/IPython/html/static/style/style.min.css +++ b/IPython/html/static/style/style.min.css @@ -1537,23 +1537,16 @@ pre,code,kbd,samp{white-space:pre-wrap;} #fonttest{font-family:monospace;} p{margin-bottom:0;} .end_space{height:200px;} -.celltoolbar{border:thin solid #CFCFCF;border-bottom:none;background:#EEE;border-top-right-radius:3px;border-top-left-radius:3px;width:100%;-webkit-box-pack:end;height:22px;display:-webkit-box;-webkit-box-orient:horizontal;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:horizontal;-moz-box-align:stretch;display:box;box-orient:horizontal;box-align:stretch;-webkit-box-direction:reverse;-moz-box-direction:reverse;box-direction:reverse;} -.no_input_radius{border-top-right-radius:0px;border-top-left-radius:0px;} -.text_cell .ctb_prompt{display:none;} -.code_cell .ctb_prompt{display:block;} +.celltoolbar{border:thin solid #CFCFCF;border-bottom:none;background:#EEE;border-radius:3px 3px 0px 0px;width:100%;-webkit-box-pack:end;height:22px;display:-webkit-box;-webkit-box-orient:horizontal;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:horizontal;-moz-box-align:stretch;display:box;box-orient:horizontal;box-align:stretch;-webkit-box-direction:reverse;-moz-box-direction:reverse;box-direction:reverse;} .ctb_hideshow{display:none;vertical-align:bottom;padding-right:2px;} .celltoolbar>div{padding-top:0px;} -.ctb_area{margin:0;padding:0;width:100%;} -.ctb_show.ctb_hideshow,.ctb_show .ctb_hideshow{display:block;} -.ctb_show .input_area,.ctb_show .ctb_hideshow+div.text_cell_input{border-top-right-radius:0px;border-top-left-radius:0px;} -.ctb_show>.celltoolbar{border-bottom-right-radius:0px;border-bottom-left-radius:0px;} -.button_container{margin-top:0;margin-bottom:0;} -.ui-button{min-width:30px;} +.ctb_global_show .ctb_show.ctb_hideshow{display:block;} +.ctb_global_show .ctb_show+.input_area,.ctb_global_show .ctb_show+div.text_cell_input{border-top-right-radius:0px;border-top-left-radius:0px;} .celltoolbar .button_container select{margin:10px;margin-top:1px;margin-bottom:0px;padding:0;font-size:87%;width:auto;display:inline-block;height:18px;line-height:18px;vertical-align:top;} .celltoolbar label{display:inline-block;height:15px;line-height:15px;vertical-align:top;} .celltoolbar label span{font-size:85%;} .celltoolbar input[type=checkbox]{margin:0px;margin-left:4px;margin-right:4px;} -.celltoolbar .ui-button{border:none;vertical-align:top;height:20px;} +.celltoolbar .ui-button{border:none;vertical-align:top;height:20px;min-width:30px;} .completions{position:absolute;z-index:10;overflow:hidden;border:1px solid #ababab;border-radius:4px;-webkit-box-shadow:0px 6px 10px -1px #adadad;-moz-box-shadow:0px 6px 10px -1px #adadad;box-shadow:0px 6px 10px -1px #adadad;} .completions select{background:white;outline:none;border:none;padding:0px;margin:0px;overflow:auto;font-family:monospace;font-size:110%;color:#000000;} .completions select option.context{color:#0064cd;} From dd3a1866ffd23e3d0936fcc3c8169b937948c0d0 Mon Sep 17 00:00:00 2001 From: MinRK Date: Wed, 6 Nov 2013 12:11:35 -0800 Subject: [PATCH 04/13] give Raw Cells a placeholder and make sure cell_type is defined *before* calling TextCell.apply --- IPython/html/static/notebook/js/cell.js | 5 ++- IPython/html/static/notebook/js/textcell.js | 42 +++++++++++---------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/IPython/html/static/notebook/js/cell.js b/IPython/html/static/notebook/js/cell.js index 4a87ba6d8..13ce3cbd5 100644 --- a/IPython/html/static/notebook/js/cell.js +++ b/IPython/html/static/notebook/js/cell.js @@ -33,9 +33,9 @@ var IPython = (function (IPython) { */ var Cell = function (options) { - options = this.mergeopt(Cell, options) + options = this.mergeopt(Cell, options); // superclass default overwrite our default - + this.placeholder = options.placeholder || ''; this.read_only = options.cm_config.readOnly; this.selected = false; @@ -80,6 +80,7 @@ var IPython = (function (IPython) { } Cell.prototype.mergeopt = function(_class, options, overwrite){ + options = options || {}; overwrite = overwrite || {}; return $.extend(true, {}, _class.options_default, options, overwrite) diff --git a/IPython/html/static/notebook/js/textcell.js b/IPython/html/static/notebook/js/textcell.js index 7e63591d0..c19e201dc 100644 --- a/IPython/html/static/notebook/js/textcell.js +++ b/IPython/html/static/notebook/js/textcell.js @@ -46,11 +46,11 @@ var IPython = (function (IPython) { options = this.mergeopt(TextCell,options,{cm_config:cm_overwrite_options}); - IPython.Cell.apply(this, [options]); + this.cell_type = this.cell_type || 'text'; + IPython.Cell.apply(this, [options]); this.rendered = false; - this.cell_type = this.cell_type || 'text'; }; TextCell.prototype = new IPython.Cell(); @@ -278,6 +278,9 @@ var IPython = (function (IPython) { var data = IPython.Cell.prototype.toJSON.apply(this); data.cell_type = this.cell_type; data.source = this.get_text(); + if (data.source == this.placeholder) { + data.source = ""; + } return data; }; @@ -288,12 +291,10 @@ var IPython = (function (IPython) { * @extends IPython.HTMLCell */ var MarkdownCell = function (options) { - var options = options || {}; - - options = this.mergeopt(MarkdownCell,options); - TextCell.apply(this, [options]); + options = this.mergeopt(MarkdownCell, options); this.cell_type = 'markdown'; + TextCell.apply(this, [options]); }; MarkdownCell.options_default = { @@ -334,7 +335,7 @@ var IPython = (function (IPython) { } this.element.find('div.text_cell_input').hide(); this.element.find("div.text_cell_render").show(); - this.typeset() + this.typeset(); this.rendered = true; } }; @@ -348,20 +349,21 @@ var IPython = (function (IPython) { * @extends IPython.TextCell */ var RawCell = function (options) { - - options = this.mergeopt(RawCell,options) - TextCell.apply(this, [options]); - + options = this.mergeopt(RawCell, options); + this.cell_type = 'raw'; + TextCell.apply(this, [options]); - var that = this + var that = this; this.element.focusout( function() { that.auto_highlight(); } ); }; RawCell.options_default = { - placeholder : "Type plain text and LaTeX: $\\alpha^2$" + placeholder : "Write raw HTML / LaTeX here, for use with nbconvert.\n" + + "It will not be rendered in the notebook.\n" + + "When passing through nbconvert, a Raw Cell's content is added to the output unmodified." }; @@ -379,7 +381,10 @@ var IPython = (function (IPython) { /** @method render **/ RawCell.prototype.render = function () { this.rendered = true; - this.edit(); + var text = this.get_text(); + if (text === "") { text = this.placeholder; } + console.log('rendering', text); + this.set_text(text); }; @@ -412,8 +417,7 @@ var IPython = (function (IPython) { /** @method select **/ RawCell.prototype.select = function () { IPython.Cell.prototype.select.apply(this); - this.code_mirror.refresh(); - this.code_mirror.focus(); + this.edit(); }; /** @method at_top **/ @@ -448,16 +452,16 @@ var IPython = (function (IPython) { * @extends IPython.TextCell */ var HeadingCell = function (options) { + options = this.mergeopt(HeadingCell, options); - options = this.mergeopt(HeadingCell,options) + this.level = 1; + this.cell_type = 'heading'; TextCell.apply(this, [options]); /** * heading level of the cell, use getter and setter to access * @property level */ - this.level = 1; - this.cell_type = 'heading'; }; HeadingCell.options_default = { From 3a17777c50197322e0d7643a05210e3781dfc436 Mon Sep 17 00:00:00 2001 From: MinRK Date: Wed, 6 Nov 2013 12:12:10 -0800 Subject: [PATCH 05/13] clarify name of 'default' cell toolbar --- .../html/static/notebook/js/celltoolbarpresets/default.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/IPython/html/static/notebook/js/celltoolbarpresets/default.js b/IPython/html/static/notebook/js/celltoolbarpresets/default.js index fb1ae464b..74210ca7c 100644 --- a/IPython/html/static/notebook/js/celltoolbarpresets/default.js +++ b/IPython/html/static/notebook/js/celltoolbarpresets/default.js @@ -28,7 +28,7 @@ var button_container = div; var button = $('