|
5 | 5 | from enum import Enum, auto |
6 | 6 | from typing import Any, ClassVar, Literal, TypeVar, cast, override |
7 | 7 |
|
8 | | -from rich.markup import escape as _escape_markup |
| 8 | +from rich.text import Text |
9 | 9 | from textual import work |
10 | 10 | from textual.app import App, ComposeResult |
11 | 11 | from textual.binding import Binding, BindingsMap |
@@ -281,7 +281,7 @@ def compose(self) -> ComposeResult: |
281 | 281 | with Container(): |
282 | 282 | yield option_list |
283 | 283 | yield Rule(orientation=rule_orientation) |
284 | | - yield ScrollableContainer(Label('', id='preview_content', markup=True)) |
| 284 | + yield ScrollableContainer(Label('', id='preview_content', markup=False)) |
285 | 285 |
|
286 | 286 | if self._filter: |
287 | 287 | yield Input(placeholder='/filter', id='filter-input') |
@@ -360,9 +360,8 @@ def _set_preview(self, item_id: str) -> None: |
360 | 360 | maybe_preview = item.preview_action(item) |
361 | 361 |
|
362 | 362 | if maybe_preview is not None: |
363 | | - if not item.preview_markup: |
364 | | - maybe_preview = _escape_markup(maybe_preview) |
365 | | - preview_widget.update(maybe_preview) |
| 363 | + content = Text.from_markup(maybe_preview) if item.preview_markup else maybe_preview |
| 364 | + preview_widget.update(content) |
366 | 365 | return |
367 | 366 |
|
368 | 367 | preview_widget.update('') |
@@ -513,7 +512,7 @@ def compose(self) -> ComposeResult: |
513 | 512 | with Container(): |
514 | 513 | yield selection_list |
515 | 514 | yield Rule(orientation=rule_orientation) |
516 | | - yield ScrollableContainer(Label('', id='preview_content', markup=True)) |
| 515 | + yield ScrollableContainer(Label('', id='preview_content', markup=False)) |
517 | 516 |
|
518 | 517 | if self._filter: |
519 | 518 | yield Input(placeholder='/filter', id='filter-input') |
@@ -604,9 +603,8 @@ def _set_preview(self, item: MenuItem) -> None: |
604 | 603 | if item.preview_action is not None: |
605 | 604 | maybe_preview = item.preview_action(item) |
606 | 605 | if maybe_preview is not None: |
607 | | - if not item.preview_markup: |
608 | | - maybe_preview = _escape_markup(maybe_preview) |
609 | | - preview_widget.update(maybe_preview) |
| 606 | + content = Text.from_markup(maybe_preview) if item.preview_markup else maybe_preview |
| 607 | + preview_widget.update(content) |
610 | 608 | return |
611 | 609 |
|
612 | 610 | preview_widget.update('') |
@@ -693,7 +691,7 @@ def compose(self) -> ComposeResult: |
693 | 691 | yield Rule(orientation='horizontal') |
694 | 692 | if self._preview_header is not None: |
695 | 693 | yield Label(self._preview_header, classes='preview-header', id='preview_header') |
696 | | - yield ScrollableContainer(Label('', id='preview_content', markup=True)) |
| 694 | + yield ScrollableContainer(Label('', id='preview_content', markup=False)) |
697 | 695 |
|
698 | 696 | yield Footer() |
699 | 697 |
|
@@ -731,9 +729,8 @@ def _update_selection(self) -> None: |
731 | 729 | else: |
732 | 730 | text = focused.preview_action(focused) |
733 | 731 | if text is not None: |
734 | | - if not focused.preview_markup: |
735 | | - text = _escape_markup(text) |
736 | | - preview.update(text) |
| 732 | + content = Text.from_markup(text) if focused.preview_markup else text |
| 733 | + preview.update(content) |
737 | 734 | else: |
738 | 735 | button.remove_class('-active') |
739 | 736 |
|
@@ -1023,7 +1020,7 @@ def compose(self) -> ComposeResult: |
1023 | 1020 | yield Rule(orientation='horizontal') |
1024 | 1021 | if self._preview_header is not None: |
1025 | 1022 | yield Label(self._preview_header, classes='preview-header', id='preview-header') |
1026 | | - yield ScrollableContainer(Label('', id='preview_content', markup=True)) |
| 1023 | + yield ScrollableContainer(Label('', id='preview_content', markup=False)) |
1027 | 1024 |
|
1028 | 1025 | yield Footer() |
1029 | 1026 |
|
@@ -1133,9 +1130,8 @@ def on_data_table_row_highlighted(self, event: DataTable.RowHighlighted) -> None |
1133 | 1130 |
|
1134 | 1131 | maybe_preview = item.preview_action(item) |
1135 | 1132 | if maybe_preview is not None: |
1136 | | - if not item.preview_markup: |
1137 | | - maybe_preview = _escape_markup(maybe_preview) |
1138 | | - preview_widget.update(maybe_preview) |
| 1133 | + content = Text.from_markup(maybe_preview) if item.preview_markup else maybe_preview |
| 1134 | + preview_widget.update(content) |
1139 | 1135 | return |
1140 | 1136 |
|
1141 | 1137 | preview_widget.update('') |
|
0 commit comments