##// END OF EJS Templates
Merge pull request #6801 from minrk/runMode...
Thomas Kluyver -
r18874:835269e6 merge
parent child Browse files
Show More
@@ -1,1 +1,1 b''
1 Subproject commit ba94581b824a62ee630dd0b92a5aea8678248a24
1 Subproject commit 563c9e74b153e9509d94fd448353eeda13f0819c
@@ -11,7 +11,8 b' define(['
11 11 'services/sessions/session',
12 12 'notebook/js/celltoolbar',
13 13 'components/marked/lib/marked',
14 'highlight',
14 'codemirror/lib/codemirror',
15 'codemirror/addon/runmode/runmode',
15 16 'notebook/js/mathjaxutils',
16 17 'base/js/keyboard',
17 18 'notebook/js/tooltip',
@@ -29,7 +30,8 b' define(['
29 30 session,
30 31 celltoolbar,
31 32 marked,
32 hljs,
33 CodeMirror,
34 runMode,
33 35 mathjaxutils,
34 36 keyboard,
35 37 tooltip,
@@ -83,19 +85,37 b' define(['
83 85 marked.setOptions({
84 86 gfm : true,
85 87 tables: true,
86 langPrefix: "language-",
87 highlight: function(code, lang) {
88 // FIXME: probably want central config for CodeMirror theme when we have js config
89 langPrefix: "cm-s-ipython language-",
90 highlight: function(code, lang, callback) {
88 91 if (!lang) {
89 92 // no language, no highlight
90 return code;
91 }
92 var highlighted;
93 try {
94 highlighted = hljs.highlight(lang, code, false);
95 } catch(err) {
96 highlighted = hljs.highlightAuto(code);
93 if (callback) {
94 callback(null, code);
95 return;
96 } else {
97 return code;
98 }
97 99 }
98 return highlighted.value;
100 utils.requireCodeMirrorMode(lang, function () {
101 var el = document.createElement("div");
102 mode = CodeMirror.getMode({}, lang);
103 if (!mode) {
104 console.log("No CodeMirror mode: " + lang);
105 callback(null, code);
106 return;
107 }
108 try {
109 CodeMirror.runMode(code, mode, el);
110 callback(null, el.innerHTML);
111 } catch (err) {
112 console.log("Failed to highlight " + lang + " code", error);
113 callback(err, code);
114 }
115 }, function (err) {
116 console.log("No CodeMirror mode: " + lang);
117 callback(err, code);
118 });
99 119 }
100 120 });
101 121 }
@@ -552,9 +552,10 b' define(['
552 552 var text_and_math = mathjaxutils.remove_math(markdown);
553 553 var text = text_and_math[0];
554 554 var math = text_and_math[1];
555 var html = marked.parser(marked.lexer(text));
556 html = mathjaxutils.replace_math(html, math);
557 toinsert.append(html);
555 marked(text, function (err, html) {
556 html = mathjaxutils.replace_math(html, math);
557 toinsert.append(html);
558 });
558 559 element.append(toinsert);
559 560 return toinsert;
560 561 };
@@ -241,34 +241,35 b' define(['
241 241 MarkdownCell.prototype.render = function () {
242 242 var cont = TextCell.prototype.render.apply(this);
243 243 if (cont) {
244 var that = this;
244 245 var text = this.get_text();
245 246 var math = null;
246 247 if (text === "") { text = this.placeholder; }
247 248 var text_and_math = mathjaxutils.remove_math(text);
248 249 text = text_and_math[0];
249 250 math = text_and_math[1];
250 var html = marked.parser(marked.lexer(text));
251 html = mathjaxutils.replace_math(html, math);
252 html = security.sanitize_html(html);
253 html = $($.parseHTML(html));
254 // add anchors to headings
255 // console.log(html);
256 html.find(":header").addBack(":header").each(function (i, h) {
257 h = $(h);
258 var hash = h.text().replace(/ /g, '-');
259 h.attr('id', hash);
260 h.append(
261 $('<a/>')
262 .addClass('anchor-link')
263 .attr('href', '#' + hash)
264 .text('¶')
265 );
266 })
267 // links in markdown cells should open in new tabs
268 html.find("a[href]").not('[href^="#"]').attr("target", "_blank");
269 this.set_rendered(html);
270 this.typeset();
271 this.events.trigger("rendered.MarkdownCell", {cell: this})
251 marked(text, function (err, html) {
252 html = mathjaxutils.replace_math(html, math);
253 html = security.sanitize_html(html);
254 html = $($.parseHTML(html));
255 // add anchors to headings
256 html.find(":header").addBack(":header").each(function (i, h) {
257 h = $(h);
258 var hash = h.text().replace(/ /g, '-');
259 h.attr('id', hash);
260 h.append(
261 $('<a/>')
262 .addClass('anchor-link')
263 .attr('href', '#' + hash)
264 .text('¶')
265 );
266 });
267 // links in markdown cells should open in new tabs
268 html.find("a[href]").not('[href^="#"]').attr("target", "_blank");
269 that.set_rendered(html);
270 that.typeset();
271 that.events.trigger("rendered.MarkdownCell", {cell: that});
272 });
272 273 }
273 274 return cont;
274 275 };
@@ -27,7 +27,6 b''
27 27 bootstrap: 'components/bootstrap/js/bootstrap.min',
28 28 bootstraptour: 'components/bootstrap-tour/build/js/bootstrap-tour.min',
29 29 jqueryui: 'components/jquery-ui/ui/minified/jquery-ui.min',
30 highlight: 'components/highlight.js/build/highlight.pack',
31 30 moment: "components/moment/moment",
32 31 codemirror: 'components/codemirror',
33 32 termjs: "components/term.js/src/term",
@@ -52,10 +51,7 b''
52 51 jqueryui: {
53 52 deps: ["jquery"],
54 53 exports: "$"
55 },
56 highlight: {
57 exports: "hljs"
58 },
54 }
59 55 }
60 56 });
61 57 </script>
@@ -153,7 +153,6 b' def find_package_data():'
153 153 pjoin(components, "es6-promise", "*.js"),
154 154 pjoin(components, "font-awesome", "fonts", "*.*"),
155 155 pjoin(components, "google-caja", "html-css-sanitizer-minified.js"),
156 pjoin(components, "highlight.js", "build", "highlight.pack.js"),
157 156 pjoin(components, "jquery", "jquery.min.js"),
158 157 pjoin(components, "jquery-ui", "ui", "minified", "jquery-ui.min.js"),
159 158 pjoin(components, "jquery-ui", "themes", "smoothness", "jquery-ui.min.css"),
General Comments 0
You need to be logged in to leave comments. Login now