Add code highlighting to markdown cells.

Stefan van der Walt 15 years ago
parent ab788fb18e
commit 3a8811e115

@ -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;
};
};

@ -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 @@
<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>

Loading…
Cancel
Save