Skip to content

Commit

Permalink
invalid tag case
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jan 10, 2025
1 parent 53dca5d commit d3fedb9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 61 deletions.
10 changes: 7 additions & 3 deletions src/textual/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from rich._wrap import divide_line
from rich.cells import set_cell_size
from rich.console import OverflowMethod
from rich.errors import MissingStyle
from rich.segment import Segment, Segments
from rich.terminal_theme import TerminalTheme
from rich.text import Text
Expand Down Expand Up @@ -744,9 +745,12 @@ def render(

@lru_cache(maxsize=1024)
def get_style(style: str, /) -> Style:
visual_style = Style.from_rich_style(
app.console.get_style(style), app.ansi_theme
)
try:
visual_style = Style.from_rich_style(
app.console.get_style(style), app.ansi_theme
)
except MissingStyle:
visual_style = Style()
return visual_style

else:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -3316,12 +3316,16 @@ def compose(self) -> ComposeResult:
def test_static_markup(snap_compare):
"""Check that markup may be disabled.
You should see two labels, the first uses markup.
The second has markup disabled, and tags should be visible.
You should see 3 labels.
This first label contains an invalid style, and should have tags removed.
The second label should have the word "markup" boldened.
The third label has markup disabled, and should show tags without styles.
"""

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

Expand Down

0 comments on commit d3fedb9

Please sign in to comment.