diff --git a/IPython/core/oinspect.py b/IPython/core/oinspect.py index 13d6268..3a80f05 100644 --- a/IPython/core/oinspect.py +++ b/IPython/core/oinspect.py @@ -553,23 +553,23 @@ class Inspector(Colorable): def format_mime(self, bundle): """Format a mimebundle being created by _make_info_unformatted into a real mimebundle""" - # First, format the field names and values for the text/plain field - text_plain = bundle['text/plain'] - if isinstance(text_plain, (list, tuple)): - text = '' - heads, bodies = list(zip(*text_plain)) - _len = max(len(h) for h in heads) - - for head, body in zip(heads, bodies): + # Format text/plain mimetype + if isinstance(bundle['text/plain'], (list, tuple)): + # bundle['text/plain'] is a list of (head, formatted body) pairs + lines = [] + _len = max(len(h) for h,_ in bundle['text/plain']) + + for head, body in bundle['text/plain']: body = body.strip('\n') delim = '\n' if '\n' in body else ' ' - text += self.__head(head+':') + (_len - len(head))*' ' +delim + body +'\n' + lines.append(f"{self.__head(head+':')}{(_len - len(head))*' '}{delim}{body}") - bundle['text/plain'] = text + bundle['text/plain'] = '\n'.join(lines) - # Next format the text/html value by joining strings if it is a list of strings + # Format the text/html mimetype if isinstance(bundle['text/html'], (list, tuple)): - bundle['text/html'] = '\n'.join(bundle['text/html']) + # bundle['text/html'] is a list of (head, formatted body) pairs + bundle['text/html'] = '\n'.join((f'