diff --git a/CHANGELOG.md b/CHANGELOG.md index 1772024442..4c7f090452 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - `Widget.move_child` would break if `before`/`after` is set to the index of the widget in `child` https://github.com/Textualize/textual/issues/1743 +- Fixed auto width text not processing markup https://github.com/Textualize/textual/issues/3918 ### Changed diff --git a/src/textual/widget.py b/src/textual/widget.py index a4fa033e1c..4ece3935b3 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -3227,7 +3227,7 @@ def _render(self) -> ConsoleRenderable | RichCast: """ renderable = self.render() if isinstance(renderable, str): - return Text(renderable) + return Text.from_markup(renderable) return renderable async def run_action(self, action: str) -> None: diff --git a/tests/test_widget.py b/tests/test_widget.py index 44dfcde739..a3b77caad9 100644 --- a/tests/test_widget.py +++ b/tests/test_widget.py @@ -421,3 +421,17 @@ def compose(self) -> ComposeResult: with pytest.raises(MountError): async with app.run_test(): pass + + +async def test_render_returns_text(): + """Test that render processes console markup when returning a string.""" + + # Regression test for https://github.com/Textualize/textual/issues/3918 + class SimpleWidget(Widget): + def render(self) -> str: + return "Hello [b]World[/b]!" + + widget = SimpleWidget() + render_result = widget._render() + assert isinstance(render_result, Text) + assert render_result.plain == "Hello World!"