Skip to content

Commit 732c6b9

Browse files
authored
Merge pull request #5536 from Textualize/fix-escape
fix markup escape
2 parents 43a5dbb + a0405ee commit 732c6b9

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## 2.0.1 - 2024-02-16
9+
10+
### Fixed
11+
12+
- Fixed escape tags in Content markup https://github.com/Textualize/textual/pull/5536
13+
814
## 2.0.0 - 2025-02-16
915

1016
### Added

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "textual"
3-
version = "2.0.0"
3+
version = "2.0.1"
44
homepage = "https://github.com/Textualize/textual"
55
repository = "https://github.com/Textualize/textual"
66
documentation = "https://textual.textualize.io/"

src/textual/markup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class MarkupError(Exception):
4848
"markup tag",
4949
open_closing_tag=r"(?<!\\)\[/",
5050
open_tag=r"(?<!\\)\[",
51-
end_tag=r"(?<!\\)\]",
5251
).extract_text()
5352

5453
expect_markup_expression = (
@@ -344,7 +343,6 @@ def process_text(template_text: str, /) -> str:
344343
return template_text
345344

346345
for token in iter_tokens:
347-
348346
token_name = token.name
349347
if token_name == "text":
350348
value = process_text(token.value.replace("\\[", "["))
@@ -353,6 +351,7 @@ def process_text(template_text: str, /) -> str:
353351

354352
elif token_name == "open_tag":
355353
tag_text = []
354+
356355
for token in iter_tokens:
357356
if token.name == "end_tag":
358357
break

tests/test_content.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,10 @@ def test_assemble():
216216
Span(28, 35, style="blue"),
217217
Span(41, 66, style="underline"),
218218
]
219+
220+
221+
def test_escape():
222+
"""Test that escaping the first square bracket."""
223+
content = Content.from_markup("\\[bold]Not really bold")
224+
assert content.plain == "[bold]Not really bold"
225+
assert content.spans == []

0 commit comments

Comments
 (0)