Show More
@@ -153,20 +153,29 b' class RichIPythonWidget(IPythonWidget):' | |||||
153 | metadata = msg['content']['metadata'] |
|
153 | metadata = msg['content']['metadata'] | |
154 | # Try to use the svg or html representations. |
|
154 | # Try to use the svg or html representations. | |
155 | # FIXME: Is this the right ordering of things to try? |
|
155 | # FIXME: Is this the right ordering of things to try? | |
156 | if 'image/svg+xml' in data: |
|
|||
157 |
|
|
156 | self.log.debug("display: %s", msg.get('content', '')) | |
|
157 | if 'image/svg+xml' in data: | |||
158 | svg = data['image/svg+xml'] |
|
158 | svg = data['image/svg+xml'] | |
159 | self._append_svg(svg, True) |
|
159 | self._append_svg(svg, True) | |
160 | elif 'image/png' in data: |
|
160 | elif 'image/png' in data: | |
161 | self.log.debug("display: %s", msg.get('content', '')) |
|
|||
162 | # PNG data is base64 encoded as it passes over the network |
|
161 | # PNG data is base64 encoded as it passes over the network | |
163 | # in a JSON structure so we decode it. |
|
162 | # in a JSON structure so we decode it. | |
164 | png = decodestring(data['image/png'].encode('ascii')) |
|
163 | png = decodestring(data['image/png'].encode('ascii')) | |
165 | self._append_png(png, True, metadata=metadata.get('image/png', None)) |
|
164 | self._append_png(png, True, metadata=metadata.get('image/png', None)) | |
166 | elif 'image/jpeg' in data and self._jpg_supported: |
|
165 | elif 'image/jpeg' in data and self._jpg_supported: | |
167 | self.log.debug("display: %s", msg.get('content', '')) |
|
|||
168 | jpg = decodestring(data['image/jpeg'].encode('ascii')) |
|
166 | jpg = decodestring(data['image/jpeg'].encode('ascii')) | |
169 | self._append_jpg(jpg, True, metadata=metadata.get('image/jpeg', None)) |
|
167 | self._append_jpg(jpg, True, metadata=metadata.get('image/jpeg', None)) | |
|
168 | elif 'text/latex' in data: | |||
|
169 | try: | |||
|
170 | png = latex_to_png(data['text/latex'], wrap=False) | |||
|
171 | except Exception: | |||
|
172 | self.log.error("Failed to render latex: %r", data['text/latex'], exc_info=True) | |||
|
173 | png = None | |||
|
174 | if png is not None: | |||
|
175 | self._append_png(png, True) | |||
|
176 | else: | |||
|
177 | # Print plain text if png can't be generated | |||
|
178 | return super(RichIPythonWidget, self)._handle_display_data(msg) | |||
170 | else: |
|
179 | else: | |
171 | # Default back to the plain text representation. |
|
180 | # Default back to the plain text representation. | |
172 | return super(RichIPythonWidget, self)._handle_display_data(msg) |
|
181 | return super(RichIPythonWidget, self)._handle_display_data(msg) |
General Comments 0
You need to be logged in to leave comments.
Login now