Skip to content

Commit

Permalink
Fix ANSI code decoding (issue 25)
Browse files Browse the repository at this point in the history
  • Loading branch information
hartwork committed Sep 22, 2013
1 parent 4db97b1 commit f277f8f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions ansi2html/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,25 @@ def _apply_regex(self, ansi):
if not params:
continue

# Special control codes. Mutate into an explicit-color css class.
if params[0] in [38, 48]:
params = ["%i-%i" % (params[0], params[2])] + params[3:]
# Turn codes into CSS classes
css_classes = []
skip_after_index = -1
for i, v in enumerate(params):
if i <= skip_after_index:
continue

if v in [38, 48]: # 256 color mode switches
try:
css_class = 'ansi%i-%i' % (params[i], params[i + 2])
except IndexError:
continue
skip_after_index = i + 2
else:
css_class = 'ansi%d' % v
css_classes.append(css_class)

# Count how many tags we're opening
n_open += 1
css_classes = ["ansi%s" % str(p) for p in params]

if self.inline:
style = [self.styles[klass].kw for klass in css_classes if
Expand Down

0 comments on commit f277f8f

Please sign in to comment.