Skip to content

Commit

Permalink
Remove <pre> from nested HTML repr (#4171)
Browse files Browse the repository at this point in the history
Using `<pre>` messes up the display of nested HTML reprs, e.g., from dask. Now
we only use the `<pre>` tag when displaying text.
  • Loading branch information
shoyer authored Jun 24, 2020
1 parent fb5fe79 commit a2dac23
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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

0 comments on commit a2dac23

Please sign in to comment.