branch: externals/comint-mime
commit 1431605940724318c403a6048049c6a32cc16b0e
Author: Augusto Stoffel <arstof...@gmail.com>
Commit: Augusto Stoffel <arstof...@gmail.com>

    Encoding workaround for images
    
    Following the code snipped in
    https://ipython.readthedocs.io/en/stable/config/shell_mimerenderer.html
    
    Fixes #8
---
 comint-mime.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/comint-mime.py b/comint-mime.py
index 323ef67..2033a55 100644
--- a/comint-mime.py
+++ b/comint-mime.py
@@ -12,9 +12,15 @@ def __COMINT_MIME_setup(types):
     from functools import partial
     from json import dumps as to_json
 
+    def encoding_workaround(data):
+        if isinstance(data, str):
+            from base64 import decodebytes
+            return decodebytes(data.encode())
+        return data
+
     MIME_TYPES = {
-        "image/png": None,
-        "image/jpeg": None,
+        "image/png": encoding_workaround,
+        "image/jpeg": encoding_workaround,
         "text/latex": str.encode,
         "text/html": str.encode,
         "application/json": lambda d: to_json(d).encode(),

Reply via email to