diff --git a/IPython/html/static/components b/IPython/html/static/components index ba94581..563c9e7 160000 --- a/IPython/html/static/components +++ b/IPython/html/static/components @@ -1 +1 @@ -Subproject commit ba94581b824a62ee630dd0b92a5aea8678248a24 +Subproject commit 563c9e74b153e9509d94fd448353eeda13f0819c diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 643818d..5bd4315 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -11,7 +11,8 @@ define([ 'services/sessions/session', 'notebook/js/celltoolbar', 'components/marked/lib/marked', - 'highlight', + 'codemirror/lib/codemirror', + 'codemirror/addon/runmode/runmode', 'notebook/js/mathjaxutils', 'base/js/keyboard', 'notebook/js/tooltip', @@ -29,7 +30,8 @@ define([ session, celltoolbar, marked, - hljs, + CodeMirror, + runMode, mathjaxutils, keyboard, tooltip, @@ -83,19 +85,37 @@ define([ marked.setOptions({ gfm : true, tables: true, - langPrefix: "language-", - highlight: function(code, lang) { + // FIXME: probably want central config for CodeMirror theme when we have js config + langPrefix: "cm-s-ipython language-", + highlight: function(code, lang, callback) { if (!lang) { // no language, no highlight - return code; - } - var highlighted; - try { - highlighted = hljs.highlight(lang, code, false); - } catch(err) { - highlighted = hljs.highlightAuto(code); + if (callback) { + callback(null, code); + return; + } else { + return code; + } } - return highlighted.value; + utils.requireCodeMirrorMode(lang, function () { + var el = document.createElement("div"); + mode = CodeMirror.getMode({}, lang); + if (!mode) { + console.log("No CodeMirror mode: " + lang); + callback(null, code); + return; + } + try { + CodeMirror.runMode(code, mode, el); + callback(null, el.innerHTML); + } catch (err) { + console.log("Failed to highlight " + lang + " code", error); + callback(err, code); + } + }, function (err) { + console.log("No CodeMirror mode: " + lang); + callback(err, code); + }); } }); } diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js index 5df95bc..ae56b94 100644 --- a/IPython/html/static/notebook/js/outputarea.js +++ b/IPython/html/static/notebook/js/outputarea.js @@ -552,9 +552,10 @@ define([ var text_and_math = mathjaxutils.remove_math(markdown); var text = text_and_math[0]; var math = text_and_math[1]; - var html = marked.parser(marked.lexer(text)); - html = mathjaxutils.replace_math(html, math); - toinsert.append(html); + marked(text, function (err, html) { + html = mathjaxutils.replace_math(html, math); + toinsert.append(html); + }); element.append(toinsert); return toinsert; }; diff --git a/IPython/html/static/notebook/js/textcell.js b/IPython/html/static/notebook/js/textcell.js index 183db40..24bd1e4 100644 --- a/IPython/html/static/notebook/js/textcell.js +++ b/IPython/html/static/notebook/js/textcell.js @@ -241,34 +241,35 @@ define([ MarkdownCell.prototype.render = function () { var cont = TextCell.prototype.render.apply(this); if (cont) { + var that = this; var text = this.get_text(); var math = null; if (text === "") { text = this.placeholder; } var text_and_math = mathjaxutils.remove_math(text); text = text_and_math[0]; math = text_and_math[1]; - var html = marked.parser(marked.lexer(text)); - html = mathjaxutils.replace_math(html, math); - html = security.sanitize_html(html); - html = $($.parseHTML(html)); - // add anchors to headings - // console.log(html); - html.find(":header").addBack(":header").each(function (i, h) { - h = $(h); - var hash = h.text().replace(/ /g, '-'); - h.attr('id', hash); - h.append( - $('') - .addClass('anchor-link') - .attr('href', '#' + hash) - .text('¶') - ); - }) - // links in markdown cells should open in new tabs - html.find("a[href]").not('[href^="#"]').attr("target", "_blank"); - this.set_rendered(html); - this.typeset(); - this.events.trigger("rendered.MarkdownCell", {cell: this}) + marked(text, function (err, html) { + html = mathjaxutils.replace_math(html, math); + html = security.sanitize_html(html); + html = $($.parseHTML(html)); + // add anchors to headings + html.find(":header").addBack(":header").each(function (i, h) { + h = $(h); + var hash = h.text().replace(/ /g, '-'); + h.attr('id', hash); + h.append( + $('') + .addClass('anchor-link') + .attr('href', '#' + hash) + .text('¶') + ); + }); + // links in markdown cells should open in new tabs + html.find("a[href]").not('[href^="#"]').attr("target", "_blank"); + that.set_rendered(html); + that.typeset(); + that.events.trigger("rendered.MarkdownCell", {cell: that}); + }); } return cont; }; diff --git a/IPython/html/templates/page.html b/IPython/html/templates/page.html index 404c6b5..93ba4b5 100644 --- a/IPython/html/templates/page.html +++ b/IPython/html/templates/page.html @@ -27,7 +27,6 @@ bootstrap: 'components/bootstrap/js/bootstrap.min', bootstraptour: 'components/bootstrap-tour/build/js/bootstrap-tour.min', jqueryui: 'components/jquery-ui/ui/minified/jquery-ui.min', - highlight: 'components/highlight.js/build/highlight.pack', moment: "components/moment/moment", codemirror: 'components/codemirror', termjs: "components/term.js/src/term", @@ -52,10 +51,7 @@ jqueryui: { deps: ["jquery"], exports: "$" - }, - highlight: { - exports: "hljs" - }, + } } }); diff --git a/setupbase.py b/setupbase.py index a604c16..3dbc6b5 100644 --- a/setupbase.py +++ b/setupbase.py @@ -153,7 +153,6 @@ def find_package_data(): pjoin(components, "es6-promise", "*.js"), pjoin(components, "font-awesome", "fonts", "*.*"), pjoin(components, "google-caja", "html-css-sanitizer-minified.js"), - pjoin(components, "highlight.js", "build", "highlight.pack.js"), pjoin(components, "jquery", "jquery.min.js"), pjoin(components, "jquery-ui", "ui", "minified", "jquery-ui.min.js"), pjoin(components, "jquery-ui", "themes", "smoothness", "jquery-ui.min.css"),