Highlight a str or Text instance. Args: text (Union[str, ~Text]): Text to highlight. Raises: TypeError: If not called with text or str. Returns: Text: A test instance with highlighting applied.
(self, text: Union[str, Text])
| 18 | """Abstract base class for highlighters.""" |
| 19 | |
| 20 | def __call__(self, text: Union[str, Text]) -> Text: |
| 21 | """Highlight a str or Text instance. |
| 22 | |
| 23 | Args: |
| 24 | text (Union[str, ~Text]): Text to highlight. |
| 25 | |
| 26 | Raises: |
| 27 | TypeError: If not called with text or str. |
| 28 | |
| 29 | Returns: |
| 30 | Text: A test instance with highlighting applied. |
| 31 | """ |
| 32 | if isinstance(text, str): |
| 33 | highlight_text = Text(text) |
| 34 | elif isinstance(text, Text): |
| 35 | highlight_text = text.copy() |
| 36 | else: |
| 37 | raise TypeError(f"str or Text instance required, not {text!r}") |
| 38 | self.highlight(highlight_text) |
| 39 | return highlight_text |
| 40 | |
| 41 | @abstractmethod |
| 42 | def highlight(self, text: Text) -> None: |