##// END OF EJS Templates
use reST in raw cell toolbar...
MinRK -
Show More
@@ -1,90 +1,90
1 1 //----------------------------------------------------------------------------
2 2 // Copyright (C) 2012 The IPython Development Team
3 3 //
4 4 // Distributed under the terms of the BSD License. The full license is in
5 5 // the file COPYING, distributed as part of this software.
6 6 //----------------------------------------------------------------------------
7 7
8 8 //============================================================================
9 9 // CellToolbar Example
10 10 //============================================================================
11 11
12 12 (function(IPython) {
13 13 "use strict";
14 14
15 15 var CellToolbar = IPython.CellToolbar;
16 16 var raw_cell_preset = [];
17 17 var utils = IPython.utils;
18 18
19 19 var select_type = CellToolbar.utils.select_ui_generator([
20 20 ["None", "-"],
21 21 ["LaTeX", "text/latex"],
22 ["restructuredText", "text/restructuredtext"],
22 ["reST", "text/restructuredtext"],
23 23 ["HTML", "text/html"],
24 ["markdown", "text/markdown"],
24 ["Markdown", "text/markdown"],
25 25 ["Python", "application/x-python"],
26 26 ["Custom", "dialog"],
27 27
28 28 ],
29 29 // setter
30 30 function(cell, value) {
31 31 if (value === "-") {
32 32 delete cell.metadata.raw_mimetype;
33 33 } else if (value === 'dialog'){
34 34 var dialog = $('<div/>').append(
35 35 $("<p/>")
36 36 .html("Set the MIME type of the raw cell:")
37 37 ).append(
38 38 $("<br/>")
39 39 ).append(
40 40 $('<input/>').attr('type','text').attr('size','25')
41 41 .val(cell.metadata.raw_mimetype || "-")
42 42 );
43 43 IPython.dialog.modal({
44 44 title: "Raw Cell MIME Type",
45 45 body: dialog,
46 46 buttons : {
47 47 "Cancel": {},
48 48 "OK": {
49 49 class: "btn-primary",
50 50 click: function () {
51 51 console.log(cell);
52 52 cell.metadata.raw_mimetype = $(this).find('input').val();
53 53 console.log(cell.metadata);
54 54 }
55 55 }
56 56 },
57 57 open : function (event, ui) {
58 58 var that = $(this);
59 59 // Upon ENTER, click the OK button.
60 60 that.find('input[type="text"]').keydown(function (event, ui) {
61 61 if (event.which === utils.keycodes.ENTER) {
62 62 that.find('.btn-primary').first().click();
63 63 return false;
64 64 }
65 65 });
66 66 that.find('input[type="text"]').focus().select();
67 67 }
68 68 });
69 69 } else {
70 70 cell.metadata.raw_mimetype = value;
71 71 }
72 72 },
73 73 //getter
74 74 function(cell) {
75 75 return cell.metadata.raw_mimetype || "";
76 76 },
77 77 // name
78 78 "Raw NBConvert Format",
79 79 // cell_types
80 80 ["raw"]
81 81 );
82 82
83 83 CellToolbar.register_callback('raw_cell.select', select_type);
84 84
85 85 raw_cell_preset.push('raw_cell.select');
86 86
87 87 CellToolbar.register_preset('Raw Cell Format', raw_cell_preset);
88 88 console.log('Raw Cell Format toolbar preset loaded.');
89 89
90 90 }(IPython)); No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now