Skip to content

Commit 6b088ea

Browse files
committed
fix pygments key error
1 parent 15df025 commit 6b088ea

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.7.2] - 2020-03-15
9+
10+
### Fixed
11+
12+
- KeyError for missing pygments style
13+
814
## [0.7.1] - 2020-03-13
915

1016
### Fixed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "rich"
33
homepage = "https://github.com/willmcgugan/rich"
44
documentation = "https://rich.readthedocs.io/en/latest/"
5-
version = "0.7.1"
5+
version = "0.7.2"
66
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
77
authors = ["Will McGugan <willmcgugan@gmail.com>"]
88
license = "MIT"

rich/syntax.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,20 @@ def _get_theme_style(self, token_type) -> Style:
122122
if token_type in self._style_cache:
123123
style = self._style_cache[token_type]
124124
else:
125-
pygments_style = self._pygments_style_class.style_for_token(token_type)
126-
color = pygments_style["color"]
127-
bgcolor = pygments_style["bgcolor"]
128-
style = Style(
129-
color="#" + color if color else "#000000",
130-
bgcolor="#" + bgcolor if bgcolor else self._background_color,
131-
bold=pygments_style["bold"],
132-
italic=pygments_style["italic"],
133-
underline=pygments_style["underline"],
134-
)
125+
try:
126+
pygments_style = self._pygments_style_class.style_for_token(token_type)
127+
except KeyError:
128+
style = Style()
129+
else:
130+
color = pygments_style["color"]
131+
bgcolor = pygments_style["bgcolor"]
132+
style = Style(
133+
color="#" + color if color else "#000000",
134+
bgcolor="#" + bgcolor if bgcolor else self._background_color,
135+
bold=pygments_style["bold"],
136+
italic=pygments_style["italic"],
137+
underline=pygments_style["underline"],
138+
)
135139
self._style_cache[token_type] = style
136140

137141
return style

0 commit comments

Comments
 (0)