|
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 | 9 | from textual import work |
9 | 10 | from textual.app import App, ComposeResult |
10 | 11 | from textual.binding import Binding, BindingsMap |
@@ -280,7 +281,7 @@ def compose(self) -> ComposeResult: |
280 | 281 | with Container(): |
281 | 282 | yield option_list |
282 | 283 | yield Rule(orientation=rule_orientation) |
283 | | - yield ScrollableContainer(Label('', id='preview_content', markup=False)) |
| 284 | + yield ScrollableContainer(Label('', id='preview_content', markup=True)) |
284 | 285 |
|
285 | 286 | if self._filter: |
286 | 287 | yield Input(placeholder='/filter', id='filter-input') |
@@ -359,6 +360,8 @@ def _set_preview(self, item_id: str) -> None: |
359 | 360 | maybe_preview = item.preview_action(item) |
360 | 361 |
|
361 | 362 | if maybe_preview is not None: |
| 363 | + if not item.preview_markup: |
| 364 | + maybe_preview = _escape_markup(maybe_preview) |
362 | 365 | preview_widget.update(maybe_preview) |
363 | 366 | return |
364 | 367 |
|
@@ -510,7 +513,7 @@ def compose(self) -> ComposeResult: |
510 | 513 | with Container(): |
511 | 514 | yield selection_list |
512 | 515 | yield Rule(orientation=rule_orientation) |
513 | | - yield ScrollableContainer(Label('', id='preview_content', markup=False)) |
| 516 | + yield ScrollableContainer(Label('', id='preview_content', markup=True)) |
514 | 517 |
|
515 | 518 | if self._filter: |
516 | 519 | yield Input(placeholder='/filter', id='filter-input') |
@@ -601,6 +604,8 @@ def _set_preview(self, item: MenuItem) -> None: |
601 | 604 | if item.preview_action is not None: |
602 | 605 | maybe_preview = item.preview_action(item) |
603 | 606 | if maybe_preview is not None: |
| 607 | + if not item.preview_markup: |
| 608 | + maybe_preview = _escape_markup(maybe_preview) |
604 | 609 | preview_widget.update(maybe_preview) |
605 | 610 | return |
606 | 611 |
|
@@ -688,7 +693,7 @@ def compose(self) -> ComposeResult: |
688 | 693 | yield Rule(orientation='horizontal') |
689 | 694 | if self._preview_header is not None: |
690 | 695 | yield Label(self._preview_header, classes='preview-header', id='preview_header') |
691 | | - yield ScrollableContainer(Label('', id='preview_content', markup=False)) |
| 696 | + yield ScrollableContainer(Label('', id='preview_content', markup=True)) |
692 | 697 |
|
693 | 698 | yield Footer() |
694 | 699 |
|
@@ -726,6 +731,8 @@ def _update_selection(self) -> None: |
726 | 731 | else: |
727 | 732 | text = focused.preview_action(focused) |
728 | 733 | if text is not None: |
| 734 | + if not focused.preview_markup: |
| 735 | + text = _escape_markup(text) |
729 | 736 | preview.update(text) |
730 | 737 | else: |
731 | 738 | button.remove_class('-active') |
@@ -1016,7 +1023,7 @@ def compose(self) -> ComposeResult: |
1016 | 1023 | yield Rule(orientation='horizontal') |
1017 | 1024 | if self._preview_header is not None: |
1018 | 1025 | yield Label(self._preview_header, classes='preview-header', id='preview-header') |
1019 | | - yield ScrollableContainer(Label('', id='preview_content', markup=False)) |
| 1026 | + yield ScrollableContainer(Label('', id='preview_content', markup=True)) |
1020 | 1027 |
|
1021 | 1028 | yield Footer() |
1022 | 1029 |
|
@@ -1126,6 +1133,8 @@ def on_data_table_row_highlighted(self, event: DataTable.RowHighlighted) -> None |
1126 | 1133 |
|
1127 | 1134 | maybe_preview = item.preview_action(item) |
1128 | 1135 | if maybe_preview is not None: |
| 1136 | + if not item.preview_markup: |
| 1137 | + maybe_preview = _escape_markup(maybe_preview) |
1129 | 1138 | preview_widget.update(maybe_preview) |
1130 | 1139 | return |
1131 | 1140 |
|
|
0 commit comments