From d7ab51b3d0eba2b854e5f985baa5cb92b7235a0a 2013-05-02 19:24:36 From: MinRK Date: 2013-05-02 19:24:36 Subject: [PATCH] use highlight.js to highlight markdown code blocks --- diff --git a/IPython/frontend/html/notebook/static/js/notebookmain.js b/IPython/frontend/html/notebook/static/js/notebookmain.js index fcc2ef7..58e3036 100644 --- a/IPython/frontend/html/notebook/static/js/notebookmain.js +++ b/IPython/frontend/html/notebook/static/js/notebookmain.js @@ -93,6 +93,24 @@ $(document).ready(function () { $([IPython.events]).on('notebook_loaded.Notebook', first_load); IPython.notebook.load_notebook($('body').data('notebookId')); + + if (marked) { + marked.setOptions({ + gfm : true, + tables: true, + langPrefix: "language-", + highlight: function(code, lang) { + console.log(lang, code); + var highlighted; + if (lang) { + highlighted = hljs.highlight(lang, code, false); + } else { + highlighted = hljs.highlightAuto(code); + } + return highlighted.value; + } + }) + } }); diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index 60be800..4d98a89 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -298,7 +298,7 @@ var IPython = (function (IPython) { MarkdownCell.options_default = { cm_config: { - mode: 'markdown' + mode: 'gfm' }, placeholder: "Type *Markdown* and LaTeX: $\\alpha^2$" } @@ -329,18 +329,6 @@ var IPython = (function (IPython) { } this.element.find('div.text_cell_input').hide(); this.element.find("div.text_cell_render").show(); - var code_snippets = this.element.find("pre > code"); - code_snippets.replaceWith(function () { - var code = $(this).html(); - /* Substitute br for newlines and   for spaces - before highlighting, since prettify doesn't - preserve those on all browsers */ - code = code.replace(/(\r\n|\n|\r)/gm, "
"); - code = code.replace(/ /gm, ' '); - code = prettyPrintOne(code); - - return '' + code + ''; - }); this.typeset() this.rendered = true; } diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index 64eaae8..73e941d 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -12,9 +12,9 @@ window.mathjax_url = "{{mathjax_url}}"; + - @@ -198,6 +198,7 @@ class="notebook_app" + @@ -205,8 +206,10 @@ class="notebook_app" + +