##// END OF EJS Templates
Adds markdown formatting to output cells
Andrew Jesaitis -
Show More
@@ -169,6 +169,24 b' def display_html(*objs, **kwargs):'
169 _display_mimetype('text/html', objs, **kwargs)
169 _display_mimetype('text/html', objs, **kwargs)
170
170
171
171
172 def display_markdown(*objs, **kwargs):
173 """Displays the Markdown representation of an object.
174
175 Parameters
176 ----------
177 objs : tuple of objects
178 The Python objects to display, or if raw=True raw markdown data to
179 display.
180 raw : bool
181 Are the data objects raw data or Python objects that need to be
182 formatted before display? [default: False]
183 metadata : dict (optional)
184 Metadata to be associated with the specific mimetype output.
185 """
186
187 _display_mimetype('text/markdown', objs, **kwargs)
188
189
172 def display_svg(*objs, **kwargs):
190 def display_svg(*objs, **kwargs):
173 """Display the SVG representation of an object.
191 """Display the SVG representation of an object.
174
192
@@ -392,6 +410,12 b' class HTML(TextDisplayObject):'
392 return self._repr_html_()
410 return self._repr_html_()
393
411
394
412
413 class Markdown(TextDisplayObject):
414
415 def _repr_markdown_(self):
416 return self.data
417
418
395 class Math(TextDisplayObject):
419 class Math(TextDisplayObject):
396
420
397 def _repr_latex_(self):
421 def _repr_latex_(self):
@@ -77,6 +77,7 b' class DisplayPublisher(Configurable):'
77
77
78 * text/plain
78 * text/plain
79 * text/html
79 * text/html
80 * text/markdown
80 * text/latex
81 * text/latex
81 * application/json
82 * application/json
82 * application/javascript
83 * application/javascript
@@ -141,6 +142,7 b' def publish_display_data(source, data, metadata=None):'
141
142
142 * text/plain
143 * text/plain
143 * text/html
144 * text/html
145 * text/markdown
144 * text/latex
146 * text/latex
145 * application/json
147 * application/json
146 * application/javascript
148 * application/javascript
@@ -129,6 +129,7 b' class DisplayFormatter(Configurable):'
129 formatter_classes = [
129 formatter_classes = [
130 PlainTextFormatter,
130 PlainTextFormatter,
131 HTMLFormatter,
131 HTMLFormatter,
132 MarkdownFormatter,
132 SVGFormatter,
133 SVGFormatter,
133 PNGFormatter,
134 PNGFormatter,
134 PDFFormatter,
135 PDFFormatter,
@@ -152,6 +153,7 b' class DisplayFormatter(Configurable):'
152
153
153 * text/plain
154 * text/plain
154 * text/html
155 * text/html
156 * text/markdown
155 * text/latex
157 * text/latex
156 * application/json
158 * application/json
157 * application/javascript
159 * application/javascript
@@ -706,6 +708,20 b' class HTMLFormatter(BaseFormatter):'
706 print_method = ObjectName('_repr_html_')
708 print_method = ObjectName('_repr_html_')
707
709
708
710
711 class MarkdownFormatter(BaseFormatter):
712 """A Markdown formatter.
713
714 To define the callables that compute the Markdown representation of your
715 objects, define a :meth:`_repr_markdown_` method or use the :meth:`for_type`
716 or :meth:`for_type_by_name` methods to register functions that handle
717 this.
718
719 The return value of this formatter should be a valid Markdown.
720 """
721 format_type = Unicode('text/markdown')
722
723 print_method = ObjectName('_repr_markdown_')
724
709 class SVGFormatter(BaseFormatter):
725 class SVGFormatter(BaseFormatter):
710 """An SVG formatter.
726 """An SVG formatter.
711
727
@@ -826,6 +842,7 b' class PDFFormatter(BaseFormatter):'
826 FormatterABC.register(BaseFormatter)
842 FormatterABC.register(BaseFormatter)
827 FormatterABC.register(PlainTextFormatter)
843 FormatterABC.register(PlainTextFormatter)
828 FormatterABC.register(HTMLFormatter)
844 FormatterABC.register(HTMLFormatter)
845 FormatterABC.register(MarkdownFormatter)
829 FormatterABC.register(SVGFormatter)
846 FormatterABC.register(SVGFormatter)
830 FormatterABC.register(PNGFormatter)
847 FormatterABC.register(PNGFormatter)
831 FormatterABC.register(PDFFormatter)
848 FormatterABC.register(PDFFormatter)
@@ -844,6 +861,7 b' def format_display_data(obj, include=None, exclude=None):'
844
861
845 * text/plain
862 * text/plain
846 * text/html
863 * text/html
864 * text/markdown
847 * text/latex
865 * text/latex
848 * application/json
866 * application/json
849 * application/javascript
867 * application/javascript
@@ -248,6 +248,7 b' var IPython = (function (IPython) {'
248 OutputArea.output_types = [
248 OutputArea.output_types = [
249 'application/javascript',
249 'application/javascript',
250 'text/html',
250 'text/html',
251 'text/markdown',
251 'text/latex',
252 'text/latex',
252 'image/svg+xml',
253 'image/svg+xml',
253 'image/png',
254 'image/png',
@@ -417,7 +418,9 b' var IPython = (function (IPython) {'
417 }
418 }
418 this._safe_append(toinsert);
419 this._safe_append(toinsert);
419 // If we just output latex, typeset it.
420 // If we just output latex, typeset it.
420 if ((json['text/latex'] !== undefined) || (json['text/html'] !== undefined)) {
421 if ((json['text/latex'] !== undefined) ||
422 (json['text/html'] !== undefined) ||
423 (json['text/markdown'] !== undefined)) {
421 this.typeset();
424 this.typeset();
422 }
425 }
423 };
426 };
@@ -488,7 +491,9 b' var IPython = (function (IPython) {'
488 if (this.append_mime_type(json, toinsert, handle_inserted)) {
491 if (this.append_mime_type(json, toinsert, handle_inserted)) {
489 this._safe_append(toinsert);
492 this._safe_append(toinsert);
490 // If we just output latex, typeset it.
493 // If we just output latex, typeset it.
491 if ((json['text/latex'] !== undefined) || (json['text/html'] !== undefined)) {
494 if ((json['text/latex'] !== undefined) ||
495 (json['text/html'] !== undefined) ||
496 (json['text/markdown'] !== undefined)) {
492 this.typeset();
497 this.typeset();
493 }
498 }
494 }
499 }
@@ -545,6 +550,20 b' var IPython = (function (IPython) {'
545 };
550 };
546
551
547
552
553 var append_markdown = function(markdown, md, element) {
554 var type = 'text/markdown';
555 var toinsert = this.create_output_subarea(md, "output_markdown", type);
556 var text_and_math = IPython.mathjaxutils.remove_math(markdown);
557 var text = text_and_math[0];
558 var math = text_and_math[1];
559 var html = marked.parser(marked.lexer(text));
560 html = IPython.mathjaxutils.replace_math(html, math);
561 toinsert.append(html);
562 element.append(toinsert);
563 return toinsert;
564 };
565
566
548 var append_javascript = function (js, md, element) {
567 var append_javascript = function (js, md, element) {
549 // We just eval the JS code, element appears in the local scope.
568 // We just eval the JS code, element appears in the local scope.
550 var type = 'application/javascript';
569 var type = 'application/javascript';
@@ -882,6 +901,7 b' var IPython = (function (IPython) {'
882 OutputArea.display_order = [
901 OutputArea.display_order = [
883 'application/javascript',
902 'application/javascript',
884 'text/html',
903 'text/html',
904 'text/markdown',
885 'text/latex',
905 'text/latex',
886 'image/svg+xml',
906 'image/svg+xml',
887 'image/png',
907 'image/png',
@@ -893,6 +913,7 b' var IPython = (function (IPython) {'
893 OutputArea.append_map = {
913 OutputArea.append_map = {
894 "text/plain" : append_text,
914 "text/plain" : append_text,
895 "text/html" : append_html,
915 "text/html" : append_html,
916 "text/markdown": append_markdown,
896 "image/svg+xml" : append_svg,
917 "image/svg+xml" : append_svg,
897 "image/png" : append_png,
918 "image/png" : append_png,
898 "image/jpeg" : append_jpeg,
919 "image/jpeg" : append_jpeg,
General Comments 0
You need to be logged in to leave comments. Login now