Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a 'text/plain' repr to Markdown and JSON #14150

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions IPython/core/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ def __html__(self):

class Markdown(TextDisplayObject):

def __repr__(self):
return self.data

def _repr_markdown_(self):
return self._data_and_metadata()

Expand Down Expand Up @@ -599,6 +602,9 @@ def __init__(self, data=None, url=None, filename=None, expanded=False, metadata=
if kwargs:
self.metadata.update(kwargs)
super(JSON, self).__init__(data=data, url=url, filename=filename)

def __repr__(self):
return self.data
Comment on lines +605 to +607
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for this !

Shouldn't the JSON text representation return something more like Json.dumps(self.data, indent=2) ?


def _check_data(self):
if self.data is not None and not isinstance(self.data, (dict, list)):
Expand Down