##// END OF EJS Templates
Backport PR #2212: catch errors in markdown javascript...
MinRK -
Show More
@@ -1,390 +1,394 b''
1 /**
1 /**
2 * Primary styles
2 * Primary styles
3 *
3 *
4 * Author: IPython Development Team
4 * Author: IPython Development Team
5 */
5 */
6
6
7
7
8 body {
8 body {
9 overflow: hidden;
9 overflow: hidden;
10 }
10 }
11
11
12 span#save_widget {
12 span#save_widget {
13 padding: 5px;
13 padding: 5px;
14 margin: 0px 0px 0px 300px;
14 margin: 0px 0px 0px 300px;
15 display:inline-block;
15 display:inline-block;
16 }
16 }
17
17
18 span#notebook_name {
18 span#notebook_name {
19 height: 1em;
19 height: 1em;
20 line-height: 1em;
20 line-height: 1em;
21 padding: 3px;
21 padding: 3px;
22 border: none;
22 border: none;
23 font-size: 146.5%;
23 font-size: 146.5%;
24 }
24 }
25
25
26 .ui-menubar-item .ui-button .ui-button-text {
26 .ui-menubar-item .ui-button .ui-button-text {
27 padding: 0.4em 1.0em;
27 padding: 0.4em 1.0em;
28 font-size: 100%;
28 font-size: 100%;
29 }
29 }
30
30
31 .ui-menu {
31 .ui-menu {
32 -moz-box-shadow: 0px 6px 10px -1px #adadad;
32 -moz-box-shadow: 0px 6px 10px -1px #adadad;
33 -webkit-box-shadow: 0px 6px 10px -1px #adadad;
33 -webkit-box-shadow: 0px 6px 10px -1px #adadad;
34 box-shadow: 0px 6px 10px -1px #adadad;
34 box-shadow: 0px 6px 10px -1px #adadad;
35 }
35 }
36
36
37 .ui-menu .ui-menu-item a {
37 .ui-menu .ui-menu-item a {
38 border: 1px solid transparent;
38 border: 1px solid transparent;
39 padding: 2px 1.6em;
39 padding: 2px 1.6em;
40 }
40 }
41
41
42 .ui-menu .ui-menu-item a.ui-state-focus {
42 .ui-menu .ui-menu-item a.ui-state-focus {
43 margin: 0;
43 margin: 0;
44 }
44 }
45
45
46 .ui-menu hr {
46 .ui-menu hr {
47 margin: 0.3em 0;
47 margin: 0.3em 0;
48 }
48 }
49
49
50 #menubar_container {
50 #menubar_container {
51 position: relative;
51 position: relative;
52 }
52 }
53
53
54 #notification {
54 #notification {
55 position: absolute;
55 position: absolute;
56 right: 3px;
56 right: 3px;
57 top: 3px;
57 top: 3px;
58 height: 25px;
58 height: 25px;
59 padding: 3px 6px;
59 padding: 3px 6px;
60 z-index: 10;
60 z-index: 10;
61 }
61 }
62
62
63 #toolbar {
63 #toolbar {
64 padding: 3px 15px;
64 padding: 3px 15px;
65 }
65 }
66
66
67 #cell_type {
67 #cell_type {
68 font-size: 85%;
68 font-size: 85%;
69 }
69 }
70
70
71
71
72 div#main_app {
72 div#main_app {
73 width: 100%;
73 width: 100%;
74 position: relative;
74 position: relative;
75 }
75 }
76
76
77 span#quick_help_area {
77 span#quick_help_area {
78 position: static;
78 position: static;
79 padding: 5px 0px;
79 padding: 5px 0px;
80 margin: 0px 0px 0px 0px;
80 margin: 0px 0px 0px 0px;
81 }
81 }
82
82
83 .help_string {
83 .help_string {
84 float: right;
84 float: right;
85 width: 170px;
85 width: 170px;
86 padding: 0px 5px;
86 padding: 0px 5px;
87 text-align: left;
87 text-align: left;
88 font-size: 85%;
88 font-size: 85%;
89 }
89 }
90
90
91 .help_string_label {
91 .help_string_label {
92 float: right;
92 float: right;
93 font-size: 85%;
93 font-size: 85%;
94 }
94 }
95
95
96 div#notebook_panel {
96 div#notebook_panel {
97 margin: 0px 0px 0px 0px;
97 margin: 0px 0px 0px 0px;
98 padding: 0px;
98 padding: 0px;
99 }
99 }
100
100
101 div#notebook {
101 div#notebook {
102 overflow-y: scroll;
102 overflow-y: scroll;
103 overflow-x: auto;
103 overflow-x: auto;
104 width: 100%;
104 width: 100%;
105 /* This spaces the cell away from the edge of the notebook area */
105 /* This spaces the cell away from the edge of the notebook area */
106 padding: 5px 5px 15px 5px;
106 padding: 5px 5px 15px 5px;
107 margin: 0px;
107 margin: 0px;
108 background-color: white;
108 background-color: white;
109 }
109 }
110
110
111 div#pager_splitter {
111 div#pager_splitter {
112 height: 8px;
112 height: 8px;
113 }
113 }
114
114
115 div#pager {
115 div#pager {
116 padding: 15px;
116 padding: 15px;
117 overflow: auto;
117 overflow: auto;
118 display: none;
118 display: none;
119 }
119 }
120
120
121 div.ui-widget-content {
121 div.ui-widget-content {
122 border: 1px solid #aaa;
122 border: 1px solid #aaa;
123 outline: none;
123 outline: none;
124 }
124 }
125
125
126 .cell {
126 .cell {
127 border: 1px solid transparent;
127 border: 1px solid transparent;
128 }
128 }
129
129
130 div.cell {
130 div.cell {
131 width: 100%;
131 width: 100%;
132 padding: 5px 5px 5px 0px;
132 padding: 5px 5px 5px 0px;
133 /* This acts as a spacer between cells, that is outside the border */
133 /* This acts as a spacer between cells, that is outside the border */
134 margin: 2px 0px 2px 0px;
134 margin: 2px 0px 2px 0px;
135 }
135 }
136
136
137 div.code_cell {
137 div.code_cell {
138 background-color: white;
138 background-color: white;
139 }
139 }
140
140
141 /* any special styling for code cells that are currently running goes here */
141 /* any special styling for code cells that are currently running goes here */
142 div.code_cell.running {
142 div.code_cell.running {
143 }
143 }
144
144
145 div.prompt {
145 div.prompt {
146 /* This needs to be wide enough for 3 digit prompt numbers: In[100]: */
146 /* This needs to be wide enough for 3 digit prompt numbers: In[100]: */
147 width: 11ex;
147 width: 11ex;
148 /* This 0.4em is tuned to match the padding on the CodeMirror editor. */
148 /* This 0.4em is tuned to match the padding on the CodeMirror editor. */
149 padding: 0.4em;
149 padding: 0.4em;
150 margin: 0px;
150 margin: 0px;
151 font-family: monospace;
151 font-family: monospace;
152 text-align:right;
152 text-align:right;
153 }
153 }
154
154
155 div.input {
155 div.input {
156 page-break-inside: avoid;
156 page-break-inside: avoid;
157 }
157 }
158
158
159 /* input_area and input_prompt must match in top border and margin for alignment */
159 /* input_area and input_prompt must match in top border and margin for alignment */
160 div.input_area {
160 div.input_area {
161 color: black;
161 color: black;
162 border: 1px solid #ddd;
162 border: 1px solid #ddd;
163 border-radius: 3px;
163 border-radius: 3px;
164 background: #f7f7f7;
164 background: #f7f7f7;
165 }
165 }
166
166
167 div.input_prompt {
167 div.input_prompt {
168 color: navy;
168 color: navy;
169 border-top: 1px solid transparent;
169 border-top: 1px solid transparent;
170 }
170 }
171
171
172 div.output_wrapper {
172 div.output_wrapper {
173 /* This is a spacer between the input and output of each cell */
173 /* This is a spacer between the input and output of each cell */
174 margin-top: 5px;
174 margin-top: 5px;
175 margin-left: 5px;
175 margin-left: 5px;
176 /* FF needs explicit width to stretch */
176 /* FF needs explicit width to stretch */
177 width: 100%;
177 width: 100%;
178 /* this position must be relative to enable descendents to be absolute within it */
178 /* this position must be relative to enable descendents to be absolute within it */
179 position: relative;
179 position: relative;
180 }
180 }
181
181
182 /* class for the output area when it should be height-limited */
182 /* class for the output area when it should be height-limited */
183 div.output_scroll {
183 div.output_scroll {
184 /* ideally, this would be max-height, but FF barfs all over that */
184 /* ideally, this would be max-height, but FF barfs all over that */
185 height: 24em;
185 height: 24em;
186 /* FF needs this *and the wrapper* to specify full width, or it will shrinkwrap */
186 /* FF needs this *and the wrapper* to specify full width, or it will shrinkwrap */
187 width: 100%;
187 width: 100%;
188
188
189 overflow: auto;
189 overflow: auto;
190 border-radius: 3px;
190 border-radius: 3px;
191 box-shadow: inset 0 2px 8px rgba(0, 0, 0, .8);
191 box-shadow: inset 0 2px 8px rgba(0, 0, 0, .8);
192 }
192 }
193
193
194 /* output div while it is collapsed */
194 /* output div while it is collapsed */
195 div.output_collapsed {
195 div.output_collapsed {
196 margin-right: 5px;
196 margin-right: 5px;
197 }
197 }
198
198
199 div.out_prompt_overlay {
199 div.out_prompt_overlay {
200 height: 100%;
200 height: 100%;
201 padding: 0px;
201 padding: 0px;
202 position: absolute;
202 position: absolute;
203 border-radius: 3px;
203 border-radius: 3px;
204 }
204 }
205
205
206 div.out_prompt_overlay:hover {
206 div.out_prompt_overlay:hover {
207 /* use inner shadow to get border that is computed the same on WebKit/FF */
207 /* use inner shadow to get border that is computed the same on WebKit/FF */
208 box-shadow: inset 0 0 1px #000;
208 box-shadow: inset 0 0 1px #000;
209 background: rgba(240, 240, 240, 0.5);
209 background: rgba(240, 240, 240, 0.5);
210 }
210 }
211
211
212 div.output_prompt {
212 div.output_prompt {
213 color: darkred;
213 color: darkred;
214 /* 5px right shift to account for margin in parent container */
214 /* 5px right shift to account for margin in parent container */
215 margin: 0 5px 0 -5px;
215 margin: 0 5px 0 -5px;
216 }
216 }
217
217
218 /* This class is the outer container of all output sections. */
218 /* This class is the outer container of all output sections. */
219 div.output_area {
219 div.output_area {
220 padding: 0px;
220 padding: 0px;
221 page-break-inside: avoid;
221 page-break-inside: avoid;
222 }
222 }
223
223
224 /* This class is for the output subarea inside the output_area and after
224 /* This class is for the output subarea inside the output_area and after
225 the prompt div. */
225 the prompt div. */
226 div.output_subarea {
226 div.output_subarea {
227 padding: 0.4em 0.4em 0.4em 0.4em;
227 padding: 0.4em 0.4em 0.4em 0.4em;
228 }
228 }
229
229
230 /* The rest of the output_* classes are for special styling of the different
230 /* The rest of the output_* classes are for special styling of the different
231 output types */
231 output types */
232
232
233 /* all text output has this class: */
233 /* all text output has this class: */
234 div.output_text {
234 div.output_text {
235 text-align: left;
235 text-align: left;
236 color: black;
236 color: black;
237 font-family: monospace;
237 font-family: monospace;
238 }
238 }
239
239
240 /* stdout/stderr are 'text' as well as 'stream', but pyout/pyerr are *not* streams */
240 /* stdout/stderr are 'text' as well as 'stream', but pyout/pyerr are *not* streams */
241 div.output_stream {
241 div.output_stream {
242 padding-top: 0.0em;
242 padding-top: 0.0em;
243 padding-bottom: 0.0em;
243 padding-bottom: 0.0em;
244 }
244 }
245 div.output_stdout {
245 div.output_stdout {
246 }
246 }
247 div.output_stderr {
247 div.output_stderr {
248 background: #fdd; /* very light red background for stderr */
248 background: #fdd; /* very light red background for stderr */
249 }
249 }
250
250
251 div.output_latex {
251 div.output_latex {
252 text-align: left;
252 text-align: left;
253 color: black;
253 color: black;
254 }
254 }
255
255
256 div.output_html {
256 div.output_html {
257 }
257 }
258
258
259 div.output_png {
259 div.output_png {
260 }
260 }
261
261
262 div.output_jpeg {
262 div.output_jpeg {
263 }
263 }
264
264
265 div.text_cell {
265 div.text_cell {
266 background-color: white;
266 background-color: white;
267 padding: 5px 5px 5px 5px;
267 padding: 5px 5px 5px 5px;
268 }
268 }
269
269
270 div.text_cell_input {
270 div.text_cell_input {
271 color: black;
271 color: black;
272 border: 1px solid #ddd;
272 border: 1px solid #ddd;
273 border-radius: 3px;
273 border-radius: 3px;
274 background: #f7f7f7;
274 background: #f7f7f7;
275 }
275 }
276
276
277 div.text_cell_render {
277 div.text_cell_render {
278 font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
278 font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
279 outline: none;
279 outline: none;
280 resize: none;
280 resize: none;
281 width: inherit;
281 width: inherit;
282 border-style: none;
282 border-style: none;
283 padding: 5px;
283 padding: 5px;
284 color: black;
284 color: black;
285 }
285 }
286
286
287 /* The following gets added to the <head> if it is detected that the user has a
287 /* The following gets added to the <head> if it is detected that the user has a
288 * monospace font with inconsistent normal/bold/italic height. See
288 * monospace font with inconsistent normal/bold/italic height. See
289 * notebookmain.js. Such fonts will have keywords vertically offset with
289 * notebookmain.js. Such fonts will have keywords vertically offset with
290 * respect to the rest of the text. The user should select a better font.
290 * respect to the rest of the text. The user should select a better font.
291 * See: https://github.com/ipython/ipython/issues/1503
291 * See: https://github.com/ipython/ipython/issues/1503
292 *
292 *
293 * .CodeMirror span {
293 * .CodeMirror span {
294 * vertical-align: bottom;
294 * vertical-align: bottom;
295 * }
295 * }
296 */
296 */
297
297
298 .CodeMirror {
298 .CodeMirror {
299 line-height: 1.231; /* Changed from 1em to our global default */
299 line-height: 1.231; /* Changed from 1em to our global default */
300 }
300 }
301
301
302 .CodeMirror-scroll {
302 .CodeMirror-scroll {
303 height: auto; /* Changed to auto to autogrow */
303 height: auto; /* Changed to auto to autogrow */
304 /* The CodeMirror docs are a bit fuzzy on if overflow-y should be hidden or visible.*/
304 /* The CodeMirror docs are a bit fuzzy on if overflow-y should be hidden or visible.*/
305 /* We have found that if it is visible, vertical scrollbars appear with font size changes.*/
305 /* We have found that if it is visible, vertical scrollbars appear with font size changes.*/
306 overflow-y: hidden;
306 overflow-y: hidden;
307 overflow-x: auto; /* Changed from auto to remove scrollbar */
307 overflow-x: auto; /* Changed from auto to remove scrollbar */
308 }
308 }
309
309
310 /* CSS font colors for translated ANSI colors. */
310 /* CSS font colors for translated ANSI colors. */
311
311
312
312
313 .ansiblack {color: black;}
313 .ansiblack {color: black;}
314 .ansired {color: darkred;}
314 .ansired {color: darkred;}
315 .ansigreen {color: darkgreen;}
315 .ansigreen {color: darkgreen;}
316 .ansiyellow {color: brown;}
316 .ansiyellow {color: brown;}
317 .ansiblue {color: darkblue;}
317 .ansiblue {color: darkblue;}
318 .ansipurple {color: darkviolet;}
318 .ansipurple {color: darkviolet;}
319 .ansicyan {color: steelblue;}
319 .ansicyan {color: steelblue;}
320 .ansigrey {color: grey;}
320 .ansigrey {color: grey;}
321 .ansibold {font-weight: bold;}
321 .ansibold {font-weight: bold;}
322
322
323 .completions {
323 .completions {
324 position: absolute;
324 position: absolute;
325 z-index: 10;
325 z-index: 10;
326 overflow: hidden;
326 overflow: hidden;
327 border: 1px solid grey;
327 border: 1px solid grey;
328 }
328 }
329
329
330 .completions select {
330 .completions select {
331 background: white;
331 background: white;
332 outline: none;
332 outline: none;
333 border: none;
333 border: none;
334 padding: 0px;
334 padding: 0px;
335 margin: 0px;
335 margin: 0px;
336 overflow: auto;
336 overflow: auto;
337 font-family: monospace;
337 font-family: monospace;
338 }
338 }
339
339
340 option.context {
340 option.context {
341 background-color: #DEF7FF;
341 background-color: #DEF7FF;
342 }
342 }
343 option.introspection {
343 option.introspection {
344 background-color: #EBF4EB;
344 background-color: #EBF4EB;
345 }
345 }
346
346
347 /*fixed part of the completion*/
347 /*fixed part of the completion*/
348 .completions p b {
348 .completions p b {
349 font-weight:bold;
349 font-weight:bold;
350 }
350 }
351
351
352 .completions p {
352 .completions p {
353 background: #DDF;
353 background: #DDF;
354 /*outline: none;
354 /*outline: none;
355 padding: 0px;*/
355 padding: 0px;*/
356 border-bottom: black solid 1px;
356 border-bottom: black solid 1px;
357 padding: 1px;
357 padding: 1px;
358 font-family: monospace;
358 font-family: monospace;
359 }
359 }
360
360
361 pre.dialog {
361 pre.dialog {
362 background-color: #f7f7f7;
362 background-color: #f7f7f7;
363 border: 1px solid #ddd;
363 border: 1px solid #ddd;
364 border-radius: 3px;
364 border-radius: 3px;
365 padding: 0.4em;
365 padding: 0.4em;
366 padding-left: 2em;
366 padding-left: 2em;
367 }
367 }
368
368
369 p.dialog {
369 p.dialog {
370 padding : 0.2em;
370 padding : 0.2em;
371 }
371 }
372
372
373 .shortcut_key {
373 .shortcut_key {
374 display: inline-block;
374 display: inline-block;
375 width: 15ex;
375 width: 15ex;
376 text-align: right;
376 text-align: right;
377 font-family: monospace;
377 font-family: monospace;
378 }
378 }
379
379
380 .shortcut_descr {
380 .shortcut_descr {
381 }
381 }
382
382
383 /* Word-wrap output correctly. This is the CSS3 spelling, though Firefox seems
383 /* Word-wrap output correctly. This is the CSS3 spelling, though Firefox seems
384 to not honor it correctly. Webkit browsers (Chrome, rekonq, Safari) do.
384 to not honor it correctly. Webkit browsers (Chrome, rekonq, Safari) do.
385 */
385 */
386 pre, code, kbd, samp { white-space: pre-wrap; }
386 pre, code, kbd, samp { white-space: pre-wrap; }
387
387
388 #fonttest {
388 #fonttest {
389 font-family: monospace;
389 font-family: monospace;
390 }
390 }
391
392 .js-error {
393 color: darkred;
394 } No newline at end of file
@@ -1,367 +1,375 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // TextCell
9 // TextCell
10 //============================================================================
10 //============================================================================
11
11
12 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
13
13
14 // TextCell base class
14 // TextCell base class
15
15
16 var TextCell = function () {
16 var TextCell = function () {
17 this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
17 this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
18 IPython.Cell.apply(this, arguments);
18 IPython.Cell.apply(this, arguments);
19 this.rendered = false;
19 this.rendered = false;
20 this.cell_type = this.cell_type || 'text';
20 this.cell_type = this.cell_type || 'text';
21 };
21 };
22
22
23
23
24 TextCell.prototype = new IPython.Cell();
24 TextCell.prototype = new IPython.Cell();
25
25
26
26
27 TextCell.prototype.create_element = function () {
27 TextCell.prototype.create_element = function () {
28 var cell = $("<div>").addClass('cell text_cell border-box-sizing');
28 var cell = $("<div>").addClass('cell text_cell border-box-sizing');
29 cell.attr('tabindex','2');
29 cell.attr('tabindex','2');
30 var input_area = $('<div/>').addClass('text_cell_input border-box-sizing');
30 var input_area = $('<div/>').addClass('text_cell_input border-box-sizing');
31 this.code_mirror = CodeMirror(input_area.get(0), {
31 this.code_mirror = CodeMirror(input_area.get(0), {
32 indentUnit : 4,
32 indentUnit : 4,
33 mode: this.code_mirror_mode,
33 mode: this.code_mirror_mode,
34 theme: 'default',
34 theme: 'default',
35 value: this.placeholder,
35 value: this.placeholder,
36 readOnly: this.read_only,
36 readOnly: this.read_only,
37 lineWrapping : true,
37 lineWrapping : true,
38 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
38 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
39 });
39 });
40 // The tabindex=-1 makes this div focusable.
40 // The tabindex=-1 makes this div focusable.
41 var render_area = $('<div/>').addClass('text_cell_render border-box-sizing').
41 var render_area = $('<div/>').addClass('text_cell_render border-box-sizing').
42 addClass('rendered_html').attr('tabindex','-1');
42 addClass('rendered_html').attr('tabindex','-1');
43 cell.append(input_area).append(render_area);
43 cell.append(input_area).append(render_area);
44 this.element = cell;
44 this.element = cell;
45 };
45 };
46
46
47
47
48 TextCell.prototype.bind_events = function () {
48 TextCell.prototype.bind_events = function () {
49 IPython.Cell.prototype.bind_events.apply(this);
49 IPython.Cell.prototype.bind_events.apply(this);
50 var that = this;
50 var that = this;
51 this.element.keydown(function (event) {
51 this.element.keydown(function (event) {
52 if (event.which === 13 && !event.shiftKey) {
52 if (event.which === 13 && !event.shiftKey) {
53 if (that.rendered) {
53 if (that.rendered) {
54 that.edit();
54 that.edit();
55 return false;
55 return false;
56 };
56 };
57 };
57 };
58 });
58 });
59 this.element.dblclick(function () {
59 this.element.dblclick(function () {
60 that.edit();
60 that.edit();
61 });
61 });
62 };
62 };
63
63
64
64
65 TextCell.prototype.handle_codemirror_keyevent = function (editor, event) {
65 TextCell.prototype.handle_codemirror_keyevent = function (editor, event) {
66 // This method gets called in CodeMirror's onKeyDown/onKeyPress
66 // This method gets called in CodeMirror's onKeyDown/onKeyPress
67 // handlers and is used to provide custom key handling. Its return
67 // handlers and is used to provide custom key handling. Its return
68 // value is used to determine if CodeMirror should ignore the event:
68 // value is used to determine if CodeMirror should ignore the event:
69 // true = ignore, false = don't ignore.
69 // true = ignore, false = don't ignore.
70
70
71 if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
71 if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
72 // Always ignore shift-enter in CodeMirror as we handle it.
72 // Always ignore shift-enter in CodeMirror as we handle it.
73 return true;
73 return true;
74 }
74 }
75 return false;
75 return false;
76 };
76 };
77
77
78
78
79 TextCell.prototype.select = function () {
79 TextCell.prototype.select = function () {
80 IPython.Cell.prototype.select.apply(this);
80 IPython.Cell.prototype.select.apply(this);
81 var output = this.element.find("div.text_cell_render");
81 var output = this.element.find("div.text_cell_render");
82 output.trigger('focus');
82 output.trigger('focus');
83 };
83 };
84
84
85
85
86 TextCell.prototype.unselect = function() {
86 TextCell.prototype.unselect = function() {
87 // render on selection of another cell
87 // render on selection of another cell
88 this.render();
88 this.render();
89 IPython.Cell.prototype.unselect.apply(this);
89 IPython.Cell.prototype.unselect.apply(this);
90 };
90 };
91
91
92
92
93 TextCell.prototype.edit = function () {
93 TextCell.prototype.edit = function () {
94 if ( this.read_only ) return;
94 if ( this.read_only ) return;
95 if (this.rendered === true) {
95 if (this.rendered === true) {
96 var text_cell = this.element;
96 var text_cell = this.element;
97 var output = text_cell.find("div.text_cell_render");
97 var output = text_cell.find("div.text_cell_render");
98 output.hide();
98 output.hide();
99 text_cell.find('div.text_cell_input').show();
99 text_cell.find('div.text_cell_input').show();
100 this.code_mirror.refresh();
100 this.code_mirror.refresh();
101 this.code_mirror.focus();
101 this.code_mirror.focus();
102 // We used to need an additional refresh() after the focus, but
102 // We used to need an additional refresh() after the focus, but
103 // it appears that this has been fixed in CM. This bug would show
103 // it appears that this has been fixed in CM. This bug would show
104 // up on FF when a newly loaded markdown cell was edited.
104 // up on FF when a newly loaded markdown cell was edited.
105 this.rendered = false;
105 this.rendered = false;
106 if (this.get_text() === this.placeholder) {
106 if (this.get_text() === this.placeholder) {
107 this.set_text('');
107 this.set_text('');
108 this.refresh();
108 this.refresh();
109 }
109 }
110 }
110 }
111 };
111 };
112
112
113
113
114 // Subclasses must define render.
114 // Subclasses must define render.
115 TextCell.prototype.render = function () {};
115 TextCell.prototype.render = function () {};
116
116
117
117
118 TextCell.prototype.get_text = function() {
118 TextCell.prototype.get_text = function() {
119 return this.code_mirror.getValue();
119 return this.code_mirror.getValue();
120 };
120 };
121
121
122
122
123 TextCell.prototype.set_text = function(text) {
123 TextCell.prototype.set_text = function(text) {
124 this.code_mirror.setValue(text);
124 this.code_mirror.setValue(text);
125 this.code_mirror.refresh();
125 this.code_mirror.refresh();
126 };
126 };
127
127
128
128
129 TextCell.prototype.get_rendered = function() {
129 TextCell.prototype.get_rendered = function() {
130 return this.element.find('div.text_cell_render').html();
130 return this.element.find('div.text_cell_render').html();
131 };
131 };
132
132
133
133
134 TextCell.prototype.set_rendered = function(text) {
134 TextCell.prototype.set_rendered = function(text) {
135 this.element.find('div.text_cell_render').html(text);
135 this.element.find('div.text_cell_render').html(text);
136 };
136 };
137
137
138
138
139 TextCell.prototype.at_top = function () {
139 TextCell.prototype.at_top = function () {
140 if (this.rendered) {
140 if (this.rendered) {
141 return true;
141 return true;
142 } else {
142 } else {
143 return false;
143 return false;
144 }
144 }
145 };
145 };
146
146
147
147
148 TextCell.prototype.at_bottom = function () {
148 TextCell.prototype.at_bottom = function () {
149 if (this.rendered) {
149 if (this.rendered) {
150 return true;
150 return true;
151 } else {
151 } else {
152 return false;
152 return false;
153 }
153 }
154 };
154 };
155
155
156
156
157 TextCell.prototype.fromJSON = function (data) {
157 TextCell.prototype.fromJSON = function (data) {
158 IPython.Cell.prototype.fromJSON.apply(this, arguments);
158 IPython.Cell.prototype.fromJSON.apply(this, arguments);
159 if (data.cell_type === this.cell_type) {
159 if (data.cell_type === this.cell_type) {
160 if (data.source !== undefined) {
160 if (data.source !== undefined) {
161 this.set_text(data.source);
161 this.set_text(data.source);
162 // make this value the starting point, so that we can only undo
162 // make this value the starting point, so that we can only undo
163 // to this state, instead of a blank cell
163 // to this state, instead of a blank cell
164 this.code_mirror.clearHistory();
164 this.code_mirror.clearHistory();
165 this.set_rendered(data.rendered || '');
165 this.set_rendered(data.rendered || '');
166 this.rendered = false;
166 this.rendered = false;
167 this.render();
167 this.render();
168 }
168 }
169 }
169 }
170 };
170 };
171
171
172
172
173 TextCell.prototype.toJSON = function () {
173 TextCell.prototype.toJSON = function () {
174 var data = IPython.Cell.prototype.toJSON.apply(this);
174 var data = IPython.Cell.prototype.toJSON.apply(this);
175 data.cell_type = this.cell_type;
175 data.cell_type = this.cell_type;
176 data.source = this.get_text();
176 data.source = this.get_text();
177 return data;
177 return data;
178 };
178 };
179
179
180
180
181 // HTMLCell
181 // HTMLCell
182
182
183 var HTMLCell = function () {
183 var HTMLCell = function () {
184 this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$";
184 this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$";
185 IPython.TextCell.apply(this, arguments);
185 IPython.TextCell.apply(this, arguments);
186 this.cell_type = 'html';
186 this.cell_type = 'html';
187 };
187 };
188
188
189
189
190 HTMLCell.prototype = new TextCell();
190 HTMLCell.prototype = new TextCell();
191
191
192
192
193 HTMLCell.prototype.render = function () {
193 HTMLCell.prototype.render = function () {
194 if (this.rendered === false) {
194 if (this.rendered === false) {
195 var text = this.get_text();
195 var text = this.get_text();
196 if (text === "") { text = this.placeholder; }
196 if (text === "") { text = this.placeholder; }
197 this.set_rendered(text);
197 this.set_rendered(text);
198 this.typeset();
198 this.typeset();
199 this.element.find('div.text_cell_input').hide();
199 this.element.find('div.text_cell_input').hide();
200 this.element.find("div.text_cell_render").show();
200 this.element.find("div.text_cell_render").show();
201 this.rendered = true;
201 this.rendered = true;
202 }
202 }
203 };
203 };
204
204
205
205
206 // MarkdownCell
206 // MarkdownCell
207
207
208 var MarkdownCell = function () {
208 var MarkdownCell = function () {
209 this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$";
209 this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$";
210 IPython.TextCell.apply(this, arguments);
210 IPython.TextCell.apply(this, arguments);
211 this.cell_type = 'markdown';
211 this.cell_type = 'markdown';
212 };
212 };
213
213
214
214
215 MarkdownCell.prototype = new TextCell();
215 MarkdownCell.prototype = new TextCell();
216
216
217
217
218 MarkdownCell.prototype.render = function () {
218 MarkdownCell.prototype.render = function () {
219 if (this.rendered === false) {
219 if (this.rendered === false) {
220 var text = this.get_text();
220 var text = this.get_text();
221 if (text === "") { text = this.placeholder; }
221 if (text === "") { text = this.placeholder; }
222 var html = IPython.markdown_converter.makeHtml(text);
222 var html = IPython.markdown_converter.makeHtml(text);
223 this.set_rendered(html);
223 try {
224 this.set_rendered(html);
225 } catch (e) {
226 console.log("Error running Javascript in Markdown:");
227 console.log(e);
228 this.set_rendered($("<div/>").addClass("js-error").html(
229 "Error rendering Markdown!<br/>" + e.toString())
230 );
231 }
224 this.typeset()
232 this.typeset()
225 this.element.find('div.text_cell_input').hide();
233 this.element.find('div.text_cell_input').hide();
226 this.element.find("div.text_cell_render").show();
234 this.element.find("div.text_cell_render").show();
227 var code_snippets = this.element.find("pre > code");
235 var code_snippets = this.element.find("pre > code");
228 code_snippets.replaceWith(function () {
236 code_snippets.replaceWith(function () {
229 var code = $(this).html();
237 var code = $(this).html();
230 /* Substitute br for newlines and &nbsp; for spaces
238 /* Substitute br for newlines and &nbsp; for spaces
231 before highlighting, since prettify doesn't
239 before highlighting, since prettify doesn't
232 preserve those on all browsers */
240 preserve those on all browsers */
233 code = code.replace(/(\r\n|\n|\r)/gm, "<br/>");
241 code = code.replace(/(\r\n|\n|\r)/gm, "<br/>");
234 code = code.replace(/ /gm, '&nbsp;');
242 code = code.replace(/ /gm, '&nbsp;');
235 code = prettyPrintOne(code);
243 code = prettyPrintOne(code);
236
244
237 return '<code class="prettyprint">' + code + '</code>';
245 return '<code class="prettyprint">' + code + '</code>';
238 });
246 });
239 this.rendered = true;
247 this.rendered = true;
240 }
248 }
241 };
249 };
242
250
243
251
244 // RawCell
252 // RawCell
245
253
246 var RawCell = function () {
254 var RawCell = function () {
247 this.placeholder = "Type plain text and LaTeX: $\\alpha^2$";
255 this.placeholder = "Type plain text and LaTeX: $\\alpha^2$";
248 this.code_mirror_mode = 'rst';
256 this.code_mirror_mode = 'rst';
249 IPython.TextCell.apply(this, arguments);
257 IPython.TextCell.apply(this, arguments);
250 this.cell_type = 'raw';
258 this.cell_type = 'raw';
251 };
259 };
252
260
253
261
254 RawCell.prototype = new TextCell();
262 RawCell.prototype = new TextCell();
255
263
256
264
257 RawCell.prototype.render = function () {
265 RawCell.prototype.render = function () {
258 this.rendered = true;
266 this.rendered = true;
259 this.edit();
267 this.edit();
260 };
268 };
261
269
262
270
263 RawCell.prototype.select = function () {
271 RawCell.prototype.select = function () {
264 IPython.Cell.prototype.select.apply(this);
272 IPython.Cell.prototype.select.apply(this);
265 this.code_mirror.refresh();
273 this.code_mirror.refresh();
266 this.code_mirror.focus();
274 this.code_mirror.focus();
267 };
275 };
268
276
269
277
270 RawCell.prototype.at_top = function () {
278 RawCell.prototype.at_top = function () {
271 var cursor = this.code_mirror.getCursor();
279 var cursor = this.code_mirror.getCursor();
272 if (cursor.line === 0) {
280 if (cursor.line === 0) {
273 return true;
281 return true;
274 } else {
282 } else {
275 return false;
283 return false;
276 }
284 }
277 };
285 };
278
286
279
287
280 RawCell.prototype.at_bottom = function () {
288 RawCell.prototype.at_bottom = function () {
281 var cursor = this.code_mirror.getCursor();
289 var cursor = this.code_mirror.getCursor();
282 if (cursor.line === (this.code_mirror.lineCount()-1)) {
290 if (cursor.line === (this.code_mirror.lineCount()-1)) {
283 return true;
291 return true;
284 } else {
292 } else {
285 return false;
293 return false;
286 }
294 }
287 };
295 };
288
296
289
297
290 // HTMLCell
298 // HTMLCell
291
299
292 var HeadingCell = function () {
300 var HeadingCell = function () {
293 this.placeholder = "Type Heading Here";
301 this.placeholder = "Type Heading Here";
294 IPython.TextCell.apply(this, arguments);
302 IPython.TextCell.apply(this, arguments);
295 this.cell_type = 'heading';
303 this.cell_type = 'heading';
296 this.level = 1;
304 this.level = 1;
297 };
305 };
298
306
299
307
300 HeadingCell.prototype = new TextCell();
308 HeadingCell.prototype = new TextCell();
301
309
302
310
303 HeadingCell.prototype.fromJSON = function (data) {
311 HeadingCell.prototype.fromJSON = function (data) {
304 if (data.level != undefined){
312 if (data.level != undefined){
305 this.level = data.level;
313 this.level = data.level;
306 }
314 }
307 IPython.TextCell.prototype.fromJSON.apply(this, arguments);
315 IPython.TextCell.prototype.fromJSON.apply(this, arguments);
308 };
316 };
309
317
310
318
311 HeadingCell.prototype.toJSON = function () {
319 HeadingCell.prototype.toJSON = function () {
312 var data = IPython.TextCell.prototype.toJSON.apply(this);
320 var data = IPython.TextCell.prototype.toJSON.apply(this);
313 data.level = this.get_level();
321 data.level = this.get_level();
314 return data;
322 return data;
315 };
323 };
316
324
317
325
318 HeadingCell.prototype.set_level = function (level) {
326 HeadingCell.prototype.set_level = function (level) {
319 this.level = level;
327 this.level = level;
320 if (this.rendered) {
328 if (this.rendered) {
321 this.rendered = false;
329 this.rendered = false;
322 this.render();
330 this.render();
323 };
331 };
324 };
332 };
325
333
326
334
327 HeadingCell.prototype.get_level = function () {
335 HeadingCell.prototype.get_level = function () {
328 return this.level;
336 return this.level;
329 };
337 };
330
338
331
339
332 HeadingCell.prototype.set_rendered = function (text) {
340 HeadingCell.prototype.set_rendered = function (text) {
333 var r = this.element.find("div.text_cell_render");
341 var r = this.element.find("div.text_cell_render");
334 r.empty();
342 r.empty();
335 r.append($('<h'+this.level+'/>').html(text));
343 r.append($('<h'+this.level+'/>').html(text));
336 };
344 };
337
345
338
346
339 HeadingCell.prototype.get_rendered = function () {
347 HeadingCell.prototype.get_rendered = function () {
340 var r = this.element.find("div.text_cell_render");
348 var r = this.element.find("div.text_cell_render");
341 return r.children().first().html();
349 return r.children().first().html();
342 };
350 };
343
351
344
352
345 HeadingCell.prototype.render = function () {
353 HeadingCell.prototype.render = function () {
346 if (this.rendered === false) {
354 if (this.rendered === false) {
347 var text = this.get_text();
355 var text = this.get_text();
348 if (text === "") { text = this.placeholder; }
356 if (text === "") { text = this.placeholder; }
349 this.set_rendered(text);
357 this.set_rendered(text);
350 this.typeset();
358 this.typeset();
351 this.element.find('div.text_cell_input').hide();
359 this.element.find('div.text_cell_input').hide();
352 this.element.find("div.text_cell_render").show();
360 this.element.find("div.text_cell_render").show();
353 this.rendered = true;
361 this.rendered = true;
354 };
362 };
355 };
363 };
356
364
357 IPython.TextCell = TextCell;
365 IPython.TextCell = TextCell;
358 IPython.HTMLCell = HTMLCell;
366 IPython.HTMLCell = HTMLCell;
359 IPython.MarkdownCell = MarkdownCell;
367 IPython.MarkdownCell = MarkdownCell;
360 IPython.RawCell = RawCell;
368 IPython.RawCell = RawCell;
361 IPython.HeadingCell = HeadingCell;
369 IPython.HeadingCell = HeadingCell;
362
370
363
371
364 return IPython;
372 return IPython;
365
373
366 }(IPython));
374 }(IPython));
367
375
General Comments 0
You need to be logged in to leave comments. Login now