Skip to content

Commit 53dca5d

Browse files
committed
fix markup false
1 parent 5bedb5a commit 53dca5d

File tree

4 files changed

+172
-4
lines changed

4 files changed

+172
-4
lines changed

src/textual/visual.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@ class VisualError(Exception):
6060
VisualType: TypeAlias = "RenderableType | SupportsVisual | Visual"
6161

6262

63-
def visualize(widget: Widget, obj: object) -> Visual:
63+
def visualize(widget: Widget, obj: object, markup: bool = True) -> Visual:
6464
"""Get a visual instance from an object.
6565
6666
If the object does not support the Visual protocol and is a Rich renderable, it
6767
will be wrapped in a [RichVisual][textual.visual.RichVisual].
6868
6969
Args:
70+
widget: The parent widget.
7071
obj: An object.
72+
markup: Enable markup.
7173
7274
Returns:
7375
A Visual instance to render the object, or `None` if there is no associated visual.
@@ -84,7 +86,7 @@ def visualize(widget: Widget, obj: object) -> Visual:
8486
if is_renderable(obj):
8587
# If it is a string, render it to Text
8688
if isinstance(obj, str):
87-
obj = widget.render_str(obj)
89+
obj = widget.render_str(obj) if markup else Text(obj)
8890

8991
if isinstance(obj, Text) and widget.allow_select:
9092
return Content.from_rich_text(

src/textual/widgets/_static.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(
7474
@property
7575
def visual(self) -> Visual:
7676
if self._visual is None:
77-
self._visual = visualize(self, self._content)
77+
self._visual = visualize(self, self._content, markup=self.markup)
7878
return self._visual
7979

8080
@property
@@ -109,5 +109,5 @@ def update(self, content: RenderableType | SupportsVisual = "") -> None:
109109
"""
110110

111111
self._content = content
112-
self._visual = visualize(self, content)
112+
self._visual = visualize(self, content, markup=self.markup)
113113
self.refresh(layout=True)
Loading

tests/snapshot_tests/test_snapshots.py

+15
Original file line numberDiff line numberDiff line change
@@ -3311,3 +3311,18 @@ def compose(self) -> ComposeResult:
33113311
yield Static("\n".join(f"This is some text {n}" for n in range(100)))
33123312

33133313
assert snap_compare(ScrollbarOpacityApp())
3314+
3315+
3316+
def test_static_markup(snap_compare):
3317+
"""Check that markup may be disabled.
3318+
3319+
You should see two labels, the first uses markup.
3320+
The second has markup disabled, and tags should be visible.
3321+
"""
3322+
3323+
class LabelApp(App):
3324+
def compose(self) -> ComposeResult:
3325+
yield Label("This allows [bold]markup[/bold]")
3326+
yield Label("This does not allow [bold]markup[/bold]", markup=False)
3327+
3328+
snap_compare(LabelApp())

0 commit comments

Comments
 (0)