Skip to content

Commit d3fedb9

Browse files
committed
invalid tag case
1 parent 53dca5d commit d3fedb9

File tree

3 files changed

+69
-61
lines changed

3 files changed

+69
-61
lines changed

src/textual/content.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from rich._wrap import divide_line
2020
from rich.cells import set_cell_size
2121
from rich.console import OverflowMethod
22+
from rich.errors import MissingStyle
2223
from rich.segment import Segment, Segments
2324
from rich.terminal_theme import TerminalTheme
2425
from rich.text import Text
@@ -744,9 +745,12 @@ def render(
744745

745746
@lru_cache(maxsize=1024)
746747
def get_style(style: str, /) -> Style:
747-
visual_style = Style.from_rich_style(
748-
app.console.get_style(style), app.ansi_theme
749-
)
748+
try:
749+
visual_style = Style.from_rich_style(
750+
app.console.get_style(style), app.ansi_theme
751+
)
752+
except MissingStyle:
753+
visual_style = Style()
750754
return visual_style
751755

752756
else:

tests/snapshot_tests/__snapshots__/test_snapshots/test_static_markup.svg

+56-56
Loading

tests/snapshot_tests/test_snapshots.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -3316,12 +3316,16 @@ def compose(self) -> ComposeResult:
33163316
def test_static_markup(snap_compare):
33173317
"""Check that markup may be disabled.
33183318
3319-
You should see two labels, the first uses markup.
3320-
The second has markup disabled, and tags should be visible.
3319+
You should see 3 labels.
3320+
3321+
This first label contains an invalid style, and should have tags removed.
3322+
The second label should have the word "markup" boldened.
3323+
The third label has markup disabled, and should show tags without styles.
33213324
"""
33223325

33233326
class LabelApp(App):
33243327
def compose(self) -> ComposeResult:
3328+
yield Label("There should be no [foo]tags or style[/foo]")
33253329
yield Label("This allows [bold]markup[/bold]")
33263330
yield Label("This does not allow [bold]markup[/bold]", markup=False)
33273331

0 commit comments

Comments
 (0)