From 3a8811e115c17d170b709dca829d8991dfdd4f15 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sun, 21 Aug 2011 14:14:16 -0700 Subject: [PATCH] Add code highlighting to markdown cells. --- IPython/frontend/html/notebook/static/js/textcell.js | 12 ++++++++++++ .../frontend/html/notebook/templates/notebook.html | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index 535c226bb..7732c3ea9 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -202,6 +202,18 @@ var IPython = (function (IPython) { MathJax.Hub.Queue(["Typeset",MathJax.Hub]); 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.rendered = true; }; }; diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index a114023a6..97bfe603e 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -24,6 +24,8 @@ + + @@ -214,6 +216,8 @@ + +