Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fastcore/nbio.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def repair_nb(nb):
def preferred_out(data, html1st=True, include_imgs=False):
preftyps = ('application/javascript', 'text/latex')
preftyps = (('text/html', 'text/markdown') if html1st else ('text/markdown', 'text/html')) + preftyps
if include_imgs: preftyps += 'image/jpeg','image/png','image/svg+xml'
if include_imgs: preftyps += 'image/jpeg','image/png','image/webp','image/gif','image/svg+xml'
preftyps += ('text/plain',)
for mt in preftyps:
if (text := data.get(mt)): return mt,text
Expand Down Expand Up @@ -547,7 +547,7 @@ def _render_md(out, html1st=True):
elif mime=='application/javascript': return 'md', fenced(f'<script>{d}</script>', '{=html}')
elif mime=='image/svg+xml': return 'md', fenced(d.strip(), '{=html}')
elif mime in ('text/markdown','text/latex'): return 'md', d.strip()
elif mime in ('image/jpeg','image/png'): return 'md', f'![](data:{mime};base64,{"".join(d.split())})'
elif mime in ('image/jpeg','image/png','image/webp','image/gif'): return 'md', f'![](data:{mime};base64,{"".join(d.split())})'
return None

def render_md(outputs, html1st=True):
Expand Down
6 changes: 4 additions & 2 deletions nbs/13_nbio.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@
"def preferred_out(data, html1st=True, include_imgs=False):\n",
" preftyps = ('application/javascript', 'text/latex')\n",
" preftyps = (('text/html', 'text/markdown') if html1st else ('text/markdown', 'text/html')) + preftyps\n",
" if include_imgs: preftyps += 'image/jpeg','image/png','image/svg+xml'\n",
" if include_imgs: preftyps += 'image/jpeg','image/png','image/webp','image/gif','image/svg+xml'\n",
" preftyps += ('text/plain',)\n",
" for mt in preftyps:\n",
" if (text := data.get(mt)): return mt,text\n",
Expand Down Expand Up @@ -2033,7 +2033,7 @@
" elif mime=='application/javascript': return 'md', fenced(f'<script>{d}</script>', '{=html}')\n",
" elif mime=='image/svg+xml': return 'md', fenced(d.strip(), '{=html}')\n",
" elif mime in ('text/markdown','text/latex'): return 'md', d.strip()\n",
" elif mime in ('image/jpeg','image/png'): return 'md', f'![](data:{mime};base64,{\"\".join(d.split())})'\n",
" elif mime in ('image/jpeg','image/png','image/webp','image/gif'): return 'md', f'![](data:{mime};base64,{\"\".join(d.split())})'\n",
" return None\n",
"\n",
"def render_md(outputs, html1st=True):\n",
Expand Down Expand Up @@ -2087,6 +2087,8 @@
"test_eq(render_md(disp, html1st=False), '**42**')\n",
"\n",
"test_eq(render_md([mk_display(image_png='abc')]), '![](data:image/png;base64,abc)')\n",
"test_eq(render_md([mk_display(image_webp='abc')]), '![](data:image/webp;base64,abc)')\n",
"test_eq(render_md([mk_display(image_gif='abc')]), '![](data:image/gif;base64,abc)')\n",
"test_eq(render_md([mk_error('oops')]), fenced('oops', 'output'))\n",
"test_eq(render_md([mk_stream('stdout', 'a `` b\\n')]), '```output\\na `` b\\n```')"
]
Expand Down
Loading