Skip to content

Commit

Permalink
Fixed default default style issue
Browse files Browse the repository at this point in the history
  • Loading branch information
harrydowning committed Apr 29, 2023
1 parent fccb12a commit 96f8452
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
project = 'Serl'
copyright = '2023, Harry Downing'
author = 'Harry Downing'
release = '0.2.1-beta'
release = '0.2.2-beta'

master_doc = 'index'

Expand Down
2 changes: 1 addition & 1 deletion src/serl/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NAME = __package__
VERSION = '0.2.1-beta'
VERSION = '0.2.2-beta'

SYSTEM_CONFIG_DIR = f'.{NAME}'
SYSTEM_CONFIG_ENV_DIR = 'environments'
Expand Down
25 changes: 12 additions & 13 deletions src/serl/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pygments.formatters import get_formatter_by_name
from pygments.styles import get_style_by_name

# SerlToken = string_to_tokentype('Token.Serl')
SerlToken = string_to_tokentype('Token.Serl')
def get_pygments_lexer(_tokens: dict, ignore: str, tokentypes: dict):
tokentypes = {t: ttype.title() for t, ttype in tokentypes.items()}
class PygmentsLexer(RegexLexer):
Expand All @@ -25,7 +25,7 @@ class PygmentsLexer(RegexLexer):
}
if ignore:
tokens['root'].append((ignore, Comment))
# tokens['root'].append(('.', SerlToken))
tokens['root'].append(('.', SerlToken))
try:
return PygmentsLexer()
except ValueError as err:
Expand All @@ -42,7 +42,7 @@ def get_pygments_style(style: StyleMeta, user_styles: dict[str, str]):
string_to_tokentype(tokentype.title()): user_style
for tokentype, user_style in user_styles.items()
}
# attrs['styles'][SerlToken] = attrs['styles'][Token]
attrs['styles'][SerlToken] = attrs['styles'][Token]
# Create class with type(...) to allow dynamic creation of attrs
PygmentsStyle = type('PygmentsStyle', (Style,), attrs)
return PygmentsStyle
Expand Down Expand Up @@ -81,16 +81,15 @@ def get_pygments_output(src: str, tokens: dict[str, str], ignore: str,
format: str, format_options: dict, style_defs_arg):
lexer = get_pygments_lexer(tokens, ignore, tokentypes)

style_name = format_options.get('style', None)
if style_name:
try:
style = get_style_by_name(style_name)
except ClassNotFound:
logger.warning(f'No Pygment style found for \'{style_name}\'. '
f'Default will be used.')
style = get_style_by_name('default')

format_options['style'] = get_pygments_style(style, user_styles)
style_name = format_options.get('style', 'default')
try:
style = get_style_by_name(style_name)
except ClassNotFound:
logger.warning(f'No Pygment style found for \'{style_name}\'. '
f'Default will be used.')
style = get_style_by_name('default')

format_options['style'] = get_pygments_style(style, user_styles)

try:
formatter = get_formatter_by_name(format, **format_options)
Expand Down

0 comments on commit 96f8452

Please sign in to comment.