resolved RESOLVED UNSUBMITTED PASS · None tool calls · 0 s · Textualize/rich
(not found in data/tasks.jsonl)
| # | Tool | Arguments | Result |
|---|---|---|---|
| No trace captured. | |||
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -55,6 +55,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Running tests in environment with `FORCE_COLOR` or `NO_COLOR` environment variables
- ansi decoder will now strip problematic private escape sequences (like `\x1b7`) https://github.com/Textualize/rich/pull/3278/
- Tree's ASCII_GUIDES and TREE_GUIDES constants promoted to class attributes
+- `rich.Text.highlight_regex` now accepts a regular expression object https://github.com/Textualize/rich/pull/3347
### Added
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -87,6 +87,7 @@ The following people have contributed to the development of Rich:
- [Pierro](https://github.com/xpierroz)
- [Bernhard Wagner](https://github.com/bwagner)
- [Aaron Beaudoin](https://github.com/AaronBeaudoin)
+- [Sam Woodward](https://github.com/PyWoody)
- [L. Yeung](https://github.com/lewis-yeung)
- [chthollyphile](https://github.com/chthollyphile)
- [Jonathan Helmus](https://github.com/jjhelmus)
--- a/rich/text.py
+++ b/rich/text.py
@@ -591,7 +591,7 @@ class Text(JupyterMixin):
def highlight_regex(
self,
- re_highlight: str,
+ re_highlight: Union[re.Pattern, str],
style: Optional[Union[GetStyleCallable, StyleType]] = None,
*,
style_prefix: str = "",
@@ -600,7 +600,7 @@ class Text(JupyterMixin):
translated to styles.
Args:
- re_highlight (str): A regular expression.
+ re_highlight (Union[re.Pattern, str]): A regular expression object or string.
style (Union[GetStyleCallable, StyleType]): Optional style to apply to whole match, or a callable
which accepts the matched text and returns a style. Defaults to None.
style_prefix (str, optional): Optional prefix to add to style group names.
@@ -612,7 +612,9 @@ class Text(JupyterMixin):
append_span = self._spans.append
_Span = Span
plain = self.plain
- for match in re.finditer(re_highlight, plain):
+ if isinstance(re_highlight, str):
+ re_highlight = re.compile(re_highlight)
+ for match in re_highlight.finditer(plain):
get_span = match.span
if style:
start, end = get_span()
........................................................................ [ 66%] ..................................... [100%] 109 passed in 0.20s