Skip to content

Commit

Permalink
repr highlighter improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Mar 29, 2020
1 parent c12443e commit 0b3e1ec
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.8.5] - 2020-03-29

### Changed

- Smarter number parsing regex for repr highlighter

### Added

- uuid highlighter for repr

## [0.8.4] - 2020-03-28

### Added
Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "rich"
homepage = "https://github.com/willmcgugan/rich"
documentation = "https://rich.readthedocs.io/en/latest/"
version = "0.8.4"
version = "0.8.5"
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
authors = ["Will McGugan <[email protected]>"]
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions rich/default_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"repr.bool_false": Style(color="bright_red", italic=True),
"repr.none": Style(color="magenta", italic=True),
"repr.url": Style(underline=True, color="bright_blue", bold=False),
"repr.uuid": Style(color="bright_yellow", bold=False),
"rule.line": Style(color="bright_green"),
"rule.text": Style(),
"repr.path": Style(color="magenta"),
Expand Down
16 changes: 14 additions & 2 deletions rich/highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ class ReprHighlighter(RegexHighlighter):
r"(?P<tag_start>\<)(?P<tag_name>\w*)(?P<tag_contents>.*?)(?P<tag_end>\>)",
r"(?P<attrib_name>\w+?)=(?P<attrib_value>\"?\w+\"?)",
r"(?P<bool_true>True)|(?P<bool_false>False)|(?P<none>None)",
r"(?P<number>\-?[0-9]+\.?[0-9]*)",
r"(?P<number>(?<!\w)\-?[0-9]+\.?[0-9]*\b)",
r"(?P<number>0x[0-9a-f]*)",
r"(?P<path>(\/\w+)+\/)",
r"(?P<filename>\/\w*\..{3,4})\s",
r"(?P<str>b?\'\'\'.*?\'\'\'|b?\'.*?\'|b?\"\"\".*?\"\"\"|b?\".*?\")",
r"(?<!\\)(?P<str>b?\'\'\'.*?(?<!\\)\'\'\'|b?\'.*?(?<!\\)\'|b?\"\"\".*?(?<!\\)\"\"\"|b?\".*?(?<!\\)\")",
r"(?P<url>https?:\/\/\S*)",
r"(?P<uuid>[a-fA-F0-9]{8}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{12})",
]


Expand All @@ -104,6 +105,17 @@ class ReprHighlighter(RegexHighlighter):
)
)

console.print(highlighter(r'"Hello \"World!\"!"'))
console.print(highlighter("b34a234-c3d42ef-3241"))
console.print(highlighter("234234"))
console.print(highlighter("0x234234"))
console.print(highlighter("234234"))
console.print(highlighter("234234 + 234234+-123"))

from uuid import uuid4

console.print(highlighter(str(uuid4())))

from .default_styles import MARKDOWN_STYLES
from pprint import PrettyPrinter

Expand Down

0 comments on commit 0b3e1ec

Please sign in to comment.