Show More
@@ -139,6 +139,7 define([ | |||||
139 | .append($('<option/>').attr('value','code').text('Code')) |
|
139 | .append($('<option/>').attr('value','code').text('Code')) | |
140 | .append($('<option/>').attr('value','markdown').text('Markdown')) |
|
140 | .append($('<option/>').attr('value','markdown').text('Markdown')) | |
141 | .append($('<option/>').attr('value','raw').text('Raw NBConvert')) |
|
141 | .append($('<option/>').attr('value','raw').text('Raw NBConvert')) | |
|
142 | .append($('<option/>').attr('value','heading').text('Heading')) | |||
142 | ); |
|
143 | ); | |
143 | }; |
|
144 | }; | |
144 |
|
145 | |||
@@ -194,6 +195,11 define([ | |||||
194 | case 'raw': |
|
195 | case 'raw': | |
195 | that.notebook.to_raw(); |
|
196 | that.notebook.to_raw(); | |
196 | break; |
|
197 | break; | |
|
198 | case 'heading': | |||
|
199 | that.notebook._warn_heading(); | |||
|
200 | that.notebook.to_heading(); | |||
|
201 | that.element.find('#cell_type').val("markdown"); | |||
|
202 | break; | |||
197 | default: |
|
203 | default: | |
198 | console.log("unrecognized cell type:", cell_type); |
|
204 | console.log("unrecognized cell type:", cell_type); | |
199 | } |
|
205 | } |
@@ -246,24 +246,6 define([ | |||||
246 | this.element.find('#to_raw').click(function () { |
|
246 | this.element.find('#to_raw').click(function () { | |
247 | that.notebook.to_raw(); |
|
247 | that.notebook.to_raw(); | |
248 | }); |
|
248 | }); | |
249 | this.element.find('#to_heading1').click(function () { |
|
|||
250 | that.notebook.to_heading(undefined, 1); |
|
|||
251 | }); |
|
|||
252 | this.element.find('#to_heading2').click(function () { |
|
|||
253 | that.notebook.to_heading(undefined, 2); |
|
|||
254 | }); |
|
|||
255 | this.element.find('#to_heading3').click(function () { |
|
|||
256 | that.notebook.to_heading(undefined, 3); |
|
|||
257 | }); |
|
|||
258 | this.element.find('#to_heading4').click(function () { |
|
|||
259 | that.notebook.to_heading(undefined, 4); |
|
|||
260 | }); |
|
|||
261 | this.element.find('#to_heading5').click(function () { |
|
|||
262 | that.notebook.to_heading(undefined, 5); |
|
|||
263 | }); |
|
|||
264 | this.element.find('#to_heading6').click(function () { |
|
|||
265 | that.notebook.to_heading(undefined, 6); |
|
|||
266 | }); |
|
|||
267 |
|
249 | |||
268 | this.element.find('#toggle_current_output').click(function () { |
|
250 | this.element.find('#toggle_current_output').click(function () { | |
269 | that.notebook.toggle_output(); |
|
251 | that.notebook.toggle_output(); |
@@ -1080,49 +1080,40 define([ | |||||
1080 | } |
|
1080 | } | |
1081 | } |
|
1081 | } | |
1082 | }; |
|
1082 | }; | |
1083 |
|
1083 | |||
|
1084 | Notebook.prototype._warn_heading = function () { | |||
|
1085 | // warn about heading cells being removed | |||
|
1086 | dialog.modal({ | |||
|
1087 | notebook: this, | |||
|
1088 | keyboard_manager: this.keyboard_manager, | |||
|
1089 | title : "Use markdown headings", | |||
|
1090 | body : $("<p/>").text( | |||
|
1091 | 'IPython no longer uses special heading cells. ' + | |||
|
1092 | 'Instead, write your headings in Markdown cells using # characters:' | |||
|
1093 | ).append($('<pre/>').text( | |||
|
1094 | '## This is a level 2 heading' | |||
|
1095 | )), | |||
|
1096 | buttons : { | |||
|
1097 | "OK" : {}, | |||
|
1098 | } | |||
|
1099 | }); | |||
|
1100 | }; | |||
|
1101 | ||||
1084 | /** |
|
1102 | /** | |
1085 |
* Turn a cell into a |
|
1103 | * Turn a cell into a markdown cell with a heading. | |
1086 | * |
|
1104 | * | |
1087 | * @method to_heading |
|
1105 | * @method to_heading | |
1088 | * @param {Number} [index] A cell's index |
|
1106 | * @param {Number} [index] A cell's index | |
1089 |
* @param {Number} [level] A heading level (e.g., 1 |
|
1107 | * @param {Number} [level] A heading level (e.g., 1 for h1) | |
1090 | */ |
|
1108 | */ | |
1091 | Notebook.prototype.to_heading = function (index, level) { |
|
1109 | Notebook.prototype.to_heading = function (index, level) { | |
|
1110 | this.to_markdown(index); | |||
1092 | level = level || 1; |
|
1111 | level = level || 1; | |
1093 | var i = this.index_or_selected(index); |
|
1112 | var i = this.index_or_selected(index); | |
1094 | if (this.is_valid_cell_index(i)) { |
|
1113 | if (this.is_valid_cell_index(i)) { | |
1095 |
var |
|
1114 | var cell = this.get_cell(i); | |
1096 | var target_cell = null; |
|
1115 | cell.set_heading_level(level); | |
1097 | if (source_cell instanceof textcell.MarkdownCell) { |
|
|||
1098 | source_cell.set_heading_level(level); |
|
|||
1099 | } else { |
|
|||
1100 | target_cell = this.insert_cell_below('markdown',i); |
|
|||
1101 | var text = source_cell.get_text(); |
|
|||
1102 | if (text === source_cell.placeholder) { |
|
|||
1103 | text = ''; |
|
|||
1104 | } |
|
|||
1105 | //metadata |
|
|||
1106 | target_cell.metadata = source_cell.metadata; |
|
|||
1107 | // We must show the editor before setting its contents |
|
|||
1108 | target_cell.unrender(); |
|
|||
1109 | target_cell.set_text(text); |
|
|||
1110 | target_cell.set_heading_level(level); |
|
|||
1111 | // make this value the starting point, so that we can only undo |
|
|||
1112 | // to this state, instead of a blank cell |
|
|||
1113 | target_cell.code_mirror.clearHistory(); |
|
|||
1114 | source_cell.element.remove(); |
|
|||
1115 | this.select(i); |
|
|||
1116 | var cursor = source_cell.code_mirror.getCursor(); |
|
|||
1117 | target_cell.code_mirror.setCursor(cursor); |
|
|||
1118 | if ((source_cell instanceof textcell.TextCell) && source_cell.rendered) { |
|
|||
1119 | target_cell.render(); |
|
|||
1120 | } |
|
|||
1121 | } |
|
|||
1122 | this.set_dirty(true); |
|
1116 | this.set_dirty(true); | |
1123 | this.events.trigger('selected_cell_type_changed.Notebook', |
|
|||
1124 | {'cell_type':'markdown',level:level} |
|
|||
1125 | ); |
|
|||
1126 | } |
|
1117 | } | |
1127 | }; |
|
1118 | }; | |
1128 |
|
1119 |
General Comments 0
You need to be logged in to leave comments.
Login now