Skip to content

Commit

Permalink
Handle "text/markdown" MIME type in display_data messages. Some ker…
Browse files Browse the repository at this point in the history
…nel (such as IRkernel) uses this to show object repr instead of `execute_result`.
  • Loading branch information
ngr-t committed Jun 7, 2017
1 parent 46e7dd9 commit a2a1c69
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,20 +366,30 @@ def _handle_display_data(self, reply: JupyterReply) -> None:
# view_output = "Saved the figure to '{out_file}'.\n".format(
# out_file=out_file.name)
# self._write_to_view(view_output)
self._logger.info("Caught image.")
for mime_data in reply.display_data:
data = mime_data["image/png"]
content = (
'<body style="background-color:white">' +
'<img alt="Out" src="data:image/png;base64,{data}" />' +
'</body>'
).format(
data=data.strip(),
bgcolor="white")
file_size = self.get_view().size()
region = sublime.Region(file_size, file_size)
self.get_view().add_phantom(HERMES_FIGURE_PHANTOMS, region, content, sublime.LAYOUT_BLOCK)
self._logger.info("Created phantom {}".format(content))
if "image/png" in mime_data:
data = mime_data["image/png"]
self._logger.info("Caught image.")
content = (
'<body style="background-color:white">' +
'<img alt="Out" src="data:image/png;base64,{data}" />' +
'</body>'
).format(
data=data.strip(),
bgcolor="white")
file_size = self.get_view().size()
region = sublime.Region(file_size, file_size)
self.get_view().add_phantom(
HERMES_FIGURE_PHANTOMS,
region,
content,
sublime.LAYOUT_BLOCK)
self._logger.info("Created phantom {}".format(content))
if "text/markdown" in mime_data:
# Some kernel (such as IRkernel) sends text in display_data.
result = mime_data["text/markdown"]
lines = "\n(display data): {result}".format(result=result)
self._write_to_view(lines)

def _output_input_code(self, code, execution_count):
line = "In[{execution_count}]: {code}".format(
Expand Down

1 comment on commit a2a1c69

@randy3k
Copy link
Member

@randy3k randy3k commented on a2a1c69 Jun 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ngr-t, would it make more sense to print text/plain in the sublime view?

Please sign in to comment.