From 889b711fd7e7f846e0f502d213aeae4533dec508 Mon Sep 17 00:00:00 2001 From: Andrew Jesaitis Date: Tue, 15 Apr 2014 20:01:20 -0400 Subject: [PATCH] Adds markdown formatting to output cells --- IPython/html/static/notebook/js/outputarea.js | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js index 7bdcb52b3..2fe1c4c2b 100644 --- a/IPython/html/static/notebook/js/outputarea.js +++ b/IPython/html/static/notebook/js/outputarea.js @@ -248,6 +248,7 @@ var IPython = (function (IPython) { OutputArea.output_types = [ 'application/javascript', 'text/html', + 'text/markdown', 'text/latex', 'image/svg+xml', 'image/png', @@ -417,7 +418,9 @@ var IPython = (function (IPython) { } this._safe_append(toinsert); // If we just output latex, typeset it. - if ((json['text/latex'] !== undefined) || (json['text/html'] !== undefined)) { + if ((json['text/latex'] !== undefined) || + (json['text/html'] !== undefined) || + (json['text/markdown'] !== undefined)) { this.typeset(); } }; @@ -488,7 +491,9 @@ var IPython = (function (IPython) { if (this.append_mime_type(json, toinsert, handle_inserted)) { this._safe_append(toinsert); // If we just output latex, typeset it. - if ((json['text/latex'] !== undefined) || (json['text/html'] !== undefined)) { + if ((json['text/latex'] !== undefined) || + (json['text/html'] !== undefined) || + (json['text/markdown'] !== undefined)) { this.typeset(); } } @@ -545,6 +550,20 @@ var IPython = (function (IPython) { }; + var append_markdown = function(markdown, md, element) { + var type = 'text/markdown'; + var toinsert = this.create_output_subarea(md, "output_markdown", type); + var text_and_math = IPython.mathjaxutils.remove_math(markdown); + var text = text_and_math[0]; + var math = text_and_math[1]; + var html = marked.parser(marked.lexer(text)); + html = IPython.mathjaxutils.replace_math(html, math); + toinsert.append(html); + element.append(toinsert); + return toinsert; + }; + + var append_javascript = function (js, md, element) { // We just eval the JS code, element appears in the local scope. var type = 'application/javascript'; @@ -882,6 +901,7 @@ var IPython = (function (IPython) { OutputArea.display_order = [ 'application/javascript', 'text/html', + 'text/markdown', 'text/latex', 'image/svg+xml', 'image/png', @@ -893,6 +913,7 @@ var IPython = (function (IPython) { OutputArea.append_map = { "text/plain" : append_text, "text/html" : append_html, + "text/markdown": append_markdown, "image/svg+xml" : append_svg, "image/png" : append_png, "image/jpeg" : append_jpeg,