Permalink
Browse files

Add code highlighting to markdown cells.

  • Loading branch information...
1 parent 4408742 commit d6a97e95c4fdc7c31e0db6f07d39f00777449f4c @stefanv stefanv committed Aug 21, 2011
@@ -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, "<br/>");
+ code = code.replace(/ /gm, '&nbsp;');
+ code = prettyPrintOne(code);
+
+ return '<code class="prettyprint">' + code + '</code>';
+ });
this.rendered = true;
};
};

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -24,6 +24,8 @@
<link rel="stylesheet" href="static/codemirror-2.12/theme/ipython.css">
<link rel="stylesheet" href="static/codemirror-2.12/theme/default.css">
+ <link rel="stylesheet" href="static/prettify/prettify.css"/>
+
<link rel="stylesheet" href="static/css/boilerplate.css" type="text/css" />
<link rel="stylesheet" href="static/css/layout.css" type="text/css" />
<link rel="stylesheet" href="static/css/base.css" type="text/css" />
@@ -214,6 +216,8 @@ <h3 class="section_header">Help</h3>
<script src="static/pagedown/Markdown.Converter.js" charset="utf-8"></script>
+<script src="static/prettify/prettify.js" charset="utf-8"></script>
+
<script src="static/js/namespace.js" type="text/javascript" charset="utf-8"></script>
<script src="static/js/utils.js" type="text/javascript" charset="utf-8"></script>
<script src="static/js/cell.js" type="text/javascript" charset="utf-8"></script>

0 comments on commit d6a97e9

Please sign in to comment.