Show More
@@ -169,6 +169,24 b' def display_html(*objs, **kwargs):' | |||
|
169 | 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 | 190 | def display_svg(*objs, **kwargs): |
|
173 | 191 | """Display the SVG representation of an object. |
|
174 | 192 | |
@@ -392,6 +410,12 b' class HTML(TextDisplayObject):' | |||
|
392 | 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 | 419 | class Math(TextDisplayObject): |
|
396 | 420 | |
|
397 | 421 | def _repr_latex_(self): |
@@ -77,6 +77,7 b' class DisplayPublisher(Configurable):' | |||
|
77 | 77 | |
|
78 | 78 | * text/plain |
|
79 | 79 | * text/html |
|
80 | * text/markdown | |
|
80 | 81 | * text/latex |
|
81 | 82 | * application/json |
|
82 | 83 | * application/javascript |
@@ -141,6 +142,7 b' def publish_display_data(source, data, metadata=None):' | |||
|
141 | 142 | |
|
142 | 143 | * text/plain |
|
143 | 144 | * text/html |
|
145 | * text/markdown | |
|
144 | 146 | * text/latex |
|
145 | 147 | * application/json |
|
146 | 148 | * application/javascript |
@@ -129,6 +129,7 b' class DisplayFormatter(Configurable):' | |||
|
129 | 129 | formatter_classes = [ |
|
130 | 130 | PlainTextFormatter, |
|
131 | 131 | HTMLFormatter, |
|
132 | MarkdownFormatter, | |
|
132 | 133 | SVGFormatter, |
|
133 | 134 | PNGFormatter, |
|
134 | 135 | PDFFormatter, |
@@ -152,6 +153,7 b' class DisplayFormatter(Configurable):' | |||
|
152 | 153 | |
|
153 | 154 | * text/plain |
|
154 | 155 | * text/html |
|
156 | * text/markdown | |
|
155 | 157 | * text/latex |
|
156 | 158 | * application/json |
|
157 | 159 | * application/javascript |
@@ -706,6 +708,20 b' class HTMLFormatter(BaseFormatter):' | |||
|
706 | 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 | 725 | class SVGFormatter(BaseFormatter): |
|
710 | 726 | """An SVG formatter. |
|
711 | 727 | |
@@ -826,6 +842,7 b' class PDFFormatter(BaseFormatter):' | |||
|
826 | 842 | FormatterABC.register(BaseFormatter) |
|
827 | 843 | FormatterABC.register(PlainTextFormatter) |
|
828 | 844 | FormatterABC.register(HTMLFormatter) |
|
845 | FormatterABC.register(MarkdownFormatter) | |
|
829 | 846 | FormatterABC.register(SVGFormatter) |
|
830 | 847 | FormatterABC.register(PNGFormatter) |
|
831 | 848 | FormatterABC.register(PDFFormatter) |
@@ -844,6 +861,7 b' def format_display_data(obj, include=None, exclude=None):' | |||
|
844 | 861 | |
|
845 | 862 | * text/plain |
|
846 | 863 | * text/html |
|
864 | * text/markdown | |
|
847 | 865 | * text/latex |
|
848 | 866 | * application/json |
|
849 | 867 | * application/javascript |
@@ -248,6 +248,7 b' var IPython = (function (IPython) {' | |||
|
248 | 248 | OutputArea.output_types = [ |
|
249 | 249 | 'application/javascript', |
|
250 | 250 | 'text/html', |
|
251 | 'text/markdown', | |
|
251 | 252 | 'text/latex', |
|
252 | 253 | 'image/svg+xml', |
|
253 | 254 | 'image/png', |
@@ -417,7 +418,9 b' var IPython = (function (IPython) {' | |||
|
417 | 418 | } |
|
418 | 419 | this._safe_append(toinsert); |
|
419 | 420 | // If we just output latex, typeset it. |
|
420 |
if ((json['text/latex'] !== undefined) || |
|
|
421 | if ((json['text/latex'] !== undefined) || | |
|
422 | (json['text/html'] !== undefined) || | |
|
423 | (json['text/markdown'] !== undefined)) { | |
|
421 | 424 | this.typeset(); |
|
422 | 425 | } |
|
423 | 426 | }; |
@@ -488,7 +491,9 b' var IPython = (function (IPython) {' | |||
|
488 | 491 | if (this.append_mime_type(json, toinsert, handle_inserted)) { |
|
489 | 492 | this._safe_append(toinsert); |
|
490 | 493 | // If we just output latex, typeset it. |
|
491 |
if ((json['text/latex'] !== undefined) || |
|
|
494 | if ((json['text/latex'] !== undefined) || | |
|
495 | (json['text/html'] !== undefined) || | |
|
496 | (json['text/markdown'] !== undefined)) { | |
|
492 | 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 | 567 | var append_javascript = function (js, md, element) { |
|
549 | 568 | // We just eval the JS code, element appears in the local scope. |
|
550 | 569 | var type = 'application/javascript'; |
@@ -882,6 +901,7 b' var IPython = (function (IPython) {' | |||
|
882 | 901 | OutputArea.display_order = [ |
|
883 | 902 | 'application/javascript', |
|
884 | 903 | 'text/html', |
|
904 | 'text/markdown', | |
|
885 | 905 | 'text/latex', |
|
886 | 906 | 'image/svg+xml', |
|
887 | 907 | 'image/png', |
@@ -893,6 +913,7 b' var IPython = (function (IPython) {' | |||
|
893 | 913 | OutputArea.append_map = { |
|
894 | 914 | "text/plain" : append_text, |
|
895 | 915 | "text/html" : append_html, |
|
916 | "text/markdown": append_markdown, | |
|
896 | 917 | "image/svg+xml" : append_svg, |
|
897 | 918 | "image/png" : append_png, |
|
898 | 919 | "image/jpeg" : append_jpeg, |
General Comments 0
You need to be logged in to leave comments.
Login now