Skip to content

Commit

Permalink
Merge pull request ipython#3531 from minrk/headingmath
Browse files Browse the repository at this point in the history
allow markdown in heading cells
  • Loading branch information
Carreau committed Jul 9, 2013
2 parents 7f515ce + df6f6ab commit 87a0b0c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions IPython/html/static/notebook/js/textcell.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var IPython = (function (IPython) {
*
* @class TextCell
* @constructor TextCell
* @extend Ipython.Cell
* @extend IPython.Cell
* @param {object|undefined} [options]
* @param [options.cm_config] {object} config to pass to CodeMirror, will extend/overwrite default config
* @param [options.placeholder] {string} default string to use when souce in empty for rendering (only use in some TextCell subclass)
Expand Down Expand Up @@ -285,7 +285,7 @@ var IPython = (function (IPython) {
/**
* @class MarkdownCell
* @constructor MarkdownCell
* @extends Ipython.HtmlCell
* @extends IPython.HTMLCell
*/
var MarkdownCell = function (options) {
var options = options || {};
Expand Down Expand Up @@ -342,7 +342,7 @@ var IPython = (function (IPython) {
/**
* @class RawCell
* @constructor RawCell
* @extends Ipython.TextCell
* @extends IPython.TextCell
*/
var RawCell = function (options) {

Expand Down Expand Up @@ -437,12 +437,12 @@ var IPython = (function (IPython) {

/**
* @class HeadingCell
* @extends Ipython.TextCell
* @extends IPython.TextCell
*/

/**
* @constructor HeadingCell
* @extends Ipython.TextCell
* @extends IPython.TextCell
*/
var HeadingCell = function (options) {

Expand Down Expand Up @@ -501,17 +501,17 @@ var IPython = (function (IPython) {
};


HeadingCell.prototype.set_rendered = function (text) {
HeadingCell.prototype.set_rendered = function (html) {
var r = this.element.find("div.text_cell_render");
r.empty();
var link = text.replace(/ /g, '_');
var link = $(html).text().replace(/ /g, '_');
r.append(
$('<h'+this.level+'/>')
.append(
$('<a/>')
.addClass('heading-anchor')
.attr('id', link)
.html(text)
.html(html)
).append(
$('<a/>')
.addClass('anchor-link')
Expand All @@ -532,7 +532,11 @@ var IPython = (function (IPython) {
if (this.rendered === false) {
var text = this.get_text();
if (text === "") { text = this.placeholder; }
this.set_rendered(text);
text = IPython.mathjaxutils.remove_math(text);
var html = marked.parser(marked.lexer(text));
html = $(IPython.mathjaxutils.replace_math(html)).html();

this.set_rendered(html);
this.typeset();
this.element.find('div.text_cell_input').hide();
this.element.find("div.text_cell_render").show();
Expand Down

0 comments on commit 87a0b0c

Please sign in to comment.