Skip to content

Commit f2b0da6

Browse files
committed
edge cases
1 parent aa19a51 commit f2b0da6

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/textual/markup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,12 @@ def process_text(template_text: str, /) -> str:
409409
if not style_stack:
410410
raise MarkupError("auto closing tag ('[/]') has nothing to close")
411411
open_position, tag_body, _ = style_stack.pop()
412-
spans.append(Span(open_position, position, tag_body))
412+
if open_position != position:
413+
spans.append(Span(open_position, position, tag_body))
413414

414415
content_text = "".join(text)
415416
text_length = len(content_text)
416-
if style_stack:
417+
if style_stack and text_length:
417418
spans.extend(
418419
[
419420
Span(position, text_length, tag_body)
@@ -425,7 +426,7 @@ def process_text(template_text: str, /) -> str:
425426

426427
content = Content(
427428
content_text,
428-
[Span(0, text_length, style), *spans] if style else spans,
429+
[Span(0, text_length, style), *spans] if (style and text_length) else spans,
429430
)
430431

431432
return content

tests/test_markup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@
136136
],
137137
),
138138
),
139+
# Edge cases
140+
("[bold][/bold]", Content("")),
141+
("[bold][/]", Content("")),
142+
("[bold]", Content("")),
143+
("", Content("")),
139144
],
140145
)
141146
def test_to_content(markup: str, content: Content):

0 commit comments

Comments
 (0)