Skip to content

Commit 5ee3c6a

Browse files
committed
More lenient markup
1 parent 9b72dc9 commit 5ee3c6a

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1717

1818
- Added experimental opt-in support for https://github.com/willmcgugan/textual-speedups
1919

20+
### Changed
21+
22+
- Content markup is now more lenient; if a 'tag' doesn't contain a valid style it will be included verbatim.
23+
2024
## [3.3.0] - 2025-06-01
2125

2226
### Fixed

src/textual/markup.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,20 @@ def process_text(template_text: str, /) -> str:
391391
text_append(text_content)
392392
position += len(text_content)
393393
else:
394-
opening_tag = "".join(tag_text).strip()
395-
style_stack.append(
396-
(position, opening_tag, normalize_markup_tag(opening_tag))
397-
)
394+
opening_tag = "".join(tag_text)
395+
396+
if not opening_tag.strip():
397+
blank_tag = f"[{opening_tag}]"
398+
text_append(blank_tag)
399+
position += len(blank_tag)
400+
else:
401+
style_stack.append(
402+
(
403+
position,
404+
opening_tag,
405+
normalize_markup_tag(opening_tag.strip()),
406+
)
407+
)
398408

399409
elif token_name == "open_closing_tag":
400410
tag_text = []

tests/test_markup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
[
1212
("", Content("")),
1313
("[", Content("[")),
14+
("[]", Content("[]")),
15+
("[ ", Content("[ ")),
16+
("[ ", Content("[ ")),
17+
("[ ]", Content("[ ]")),
1418
("[0", Content("[0")),
1519
("[0]", Content("[0]")),
1620
("[red", Content("[red")),

0 commit comments

Comments
 (0)