Skip to content

Commit 3bc4fb7

Browse files
authored
fix(markdown): render softbreak split links (#2811)
* fix(markdown): render softbreak split links * add test
1 parent c6bfeef commit 3bc4fb7

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/textual/widgets/_markdown.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ def update(self, markdown: str) -> AwaitMount:
738738
if child.type == "hardbreak":
739739
content.append("\n")
740740
if child.type == "softbreak":
741-
content.append(" ")
741+
content.append(" ", style_stack[-1])
742742
elif child.type == "code_inline":
743743
content.append(
744744
child.content,

tests/test_markdown.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import pytest
88
from markdown_it.token import Token
9+
from rich.style import Style
10+
from rich.text import Span
911

1012
import textual.widgets._markdown as MD
1113
from textual.app import App, ComposeResult
@@ -89,3 +91,27 @@ def markdown_nodes(root: Widget) -> Iterator[MarkdownBlock]:
8991
assert [
9092
node.__class__ for node in markdown_nodes(pilot.app.query_one(Markdown))
9193
] == expected_nodes
94+
95+
96+
async def test_softbreak_split_links_rendered_correctly() -> None:
97+
"""Test for https://github.com/Textualize/textual/issues/2805"""
98+
99+
document = """\
100+
My site [has
101+
this
102+
URL](https://example.com)\
103+
"""
104+
async with MarkdownApp(document).run_test() as pilot:
105+
markdown = pilot.app.query_one(Markdown)
106+
paragraph = markdown.children[0]
107+
assert isinstance(paragraph, MD.MarkdownParagraph)
108+
assert paragraph._text.plain == "My site has this URL"
109+
expected_spans = [
110+
Span(0, 8, Style()),
111+
Span(8, 11, Style(meta={"@click": "link('https://example.com')"})),
112+
Span(11, 12, Style(meta={"@click": "link('https://example.com')"})),
113+
Span(12, 16, Style(meta={"@click": "link('https://example.com')"})),
114+
Span(16, 17, Style(meta={"@click": "link('https://example.com')"})),
115+
Span(17, 20, Style(meta={"@click": "link('https://example.com')"})),
116+
]
117+
assert paragraph._text.spans == expected_spans

0 commit comments

Comments
 (0)