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

Remove <pre> from nested HTML repr #4171

Merged
merged 1 commit into from
Jun 24, 2020
Merged
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
8 changes: 5 additions & 3 deletions xarray/core/formatting_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def short_data_repr_html(array):
internal_data = getattr(array, "variable", array)._data
if hasattr(internal_data, "_repr_html_"):
return internal_data._repr_html_()
return escape(short_data_repr(array))
else:
text = escape(short_data_repr(array))
return f"<pre>{text}</pre>"


def format_dims(dims, coord_names):
Expand Down Expand Up @@ -123,7 +125,7 @@ def summarize_variable(name, var, is_index=False, dtype=None, preview=None):
f"<label for='{data_id}' title='Show/Hide data repr'>"
f"{data_icon}</label>"
f"<div class='xr-var-attrs'>{attrs_ul}</div>"
f"<pre class='xr-var-data'>{data_repr}</pre>"
f"<div class='xr-var-data'>{data_repr}</div>"
)


Expand Down Expand Up @@ -193,7 +195,7 @@ def array_section(obj):
f"<input id='{data_id}' class='xr-array-in' type='checkbox' {collapsed}>"
f"<label for='{data_id}' title='Show/hide data repr'>{data_icon}</label>"
f"<div class='xr-array-preview xr-preview'><span>{preview}</span></div>"
f"<pre class='xr-array-data'>{data_repr}</pre>"
f"<div class='xr-array-data'>{data_repr}</div>"
"</div>"
)

Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_formatting_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def dataset():

def test_short_data_repr_html(dataarray):
data_repr = fh.short_data_repr_html(dataarray)
assert data_repr.startswith("array")
assert data_repr.startswith("<pre>array")


def test_short_data_repr_html_non_str_keys(dataset):
Expand Down