diff --git a/rich/console.py b/rich/console.py
index c1947ce7..dc59fe38 100644
--- a/rich/console.py
+++ b/rich/console.py
@@ -2302,7 +2302,7 @@ class Console:
def escape_text(text: str) -> str:
"""HTML escape text and replace spaces with nbsp."""
- return escape(text).replace(" ", "\u00A0")
+ return escape(text).replace(" ", " ")
def make_tag(
name: str, content: Optional[str] = None, **attribs: object
@@ -2346,12 +2346,14 @@ class Console:
class_name = f"r{classes[rules]}"
if style.reverse:
+ has_background = True
background = (
_theme.foreground_color.hex
if style.color is None
else style.color.get_truecolor(_theme).hex
)
else:
+ has_background = style.bgcolor is not None
background = (
_theme.background_color.hex
if style.bgcolor is None
@@ -2359,7 +2361,7 @@ class Console:
)
text_length = cell_len(text)
- if background is not None:
+ if has_background:
text_backgrounds.append(
make_tag(
"rect",
diff --git a/tests/test_console.py b/tests/test_console.py
index fc3b19a6..cdddf09a 100644
--- a/tests/test_console.py
+++ b/tests/test_console.py
@@ -493,7 +493,7 @@ def test_export_html_inline():
assert html == expected
-EXPECTED_SVG = '\n'
+EXPECTED_SVG = '\n'
def test_export_svg():
@@ -515,7 +515,7 @@ def test_save_svg():
with tempfile.TemporaryDirectory() as path:
export_path = os.path.join(path, "example.svg")
console.save_svg(export_path)
- with open(export_path, "rt") as svg_file:
+ with open(export_path, "rt", encoding="utf-8") as svg_file:
assert svg_file.read() == EXPECTED_SVG