From a2dac231cd946893d9fc51219b0c053e04fa7fb7 Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Wed, 24 Jun 2020 08:44:59 -0700 Subject: [PATCH] Remove
 from nested HTML repr (#4171)

Using `
` messes up the display of nested HTML reprs, e.g., from dask. Now
we only use the `
` tag when displaying text.
---
 xarray/core/formatting_html.py       | 8 +++++---
 xarray/tests/test_formatting_html.py | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/xarray/core/formatting_html.py b/xarray/core/formatting_html.py
index 69832d6ca3d..c99683e91c7 100644
--- a/xarray/core/formatting_html.py
+++ b/xarray/core/formatting_html.py
@@ -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"
{text}
" def format_dims(dims, coord_names): @@ -123,7 +125,7 @@ def summarize_variable(name, var, is_index=False, dtype=None, preview=None): f"" f"
{attrs_ul}
" - f"
{data_repr}
" + f"
{data_repr}
" ) @@ -193,7 +195,7 @@ def array_section(obj): f"" f"" f"
{preview}
" - f"
{data_repr}
" + f"
{data_repr}
" "" ) diff --git a/xarray/tests/test_formatting_html.py b/xarray/tests/test_formatting_html.py index 90e74f1f78f..ea636403318 100644 --- a/xarray/tests/test_formatting_html.py +++ b/xarray/tests/test_formatting_html.py @@ -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("
array")
 
 
 def test_short_data_repr_html_non_str_keys(dataset):