Skip to content

Commit ea81389

Browse files
authored
Merge pull request #4324 from davep/the-space-must-not-flow
Squish whitespace in `Markdown`
2 parents a5ecd2a + 352d991 commit ea81389

File tree

4 files changed

+237
-1
lines changed

4 files changed

+237
-1
lines changed

src/textual/widgets/_markdown.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import re
34
from pathlib import Path, PurePath
45
from typing import Callable, Iterable, Optional
56

@@ -149,7 +150,12 @@ def build_from_token(self, token: Token) -> None:
149150
if token.children:
150151
for child in token.children:
151152
if child.type == "text":
152-
content.append(child.content, style_stack[-1])
153+
content.append(
154+
# Ensure repeating spaces and/or tabs get squashed
155+
# down to a single space.
156+
re.sub(r"\s+", " ", child.content),
157+
style_stack[-1],
158+
)
153159
if child.type == "hardbreak":
154160
content.append("\n")
155161
if child.type == "softbreak":

0 commit comments

Comments
 (0)