parent
33dc4ff2e3
commit
3f895ac112
|
@ -23,11 +23,19 @@ class Highlighter:
|
|||
def display(self, token_colors={}, debug=False):
|
||||
for group in self.tokens:
|
||||
for token in group:
|
||||
if token.name in token_colors:
|
||||
color_name = token_colors[token.name]
|
||||
color_name = None
|
||||
name_parts = token.name.split('.')
|
||||
for i in range(0, len(name_parts)):
|
||||
if '.'.join(name_parts[i:]) in token_colors:
|
||||
color_name = token_colors['.'.join(name_parts[i:])]
|
||||
break
|
||||
if color_name is not None:
|
||||
sys.stdout.write(color_dict[color_name])
|
||||
elif debug:
|
||||
raise Exception, "no highlighting for %r" % token.name
|
||||
else:
|
||||
color_name = 'white'
|
||||
sys.stdout.write(color_dict[color_name])
|
||||
sys.stdout.write(token.string)
|
||||
sys.stdout.write('\n')
|
||||
|
||||
|
|
Loading…
Reference in New Issue