Skip to content

Commit

Permalink
Enhance pygemntize
Browse files Browse the repository at this point in the history
  • Loading branch information
chhsiao90 committed Sep 13, 2016
1 parent d9df437 commit 717499a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gviewer/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@


def pygmentize(content, lexer):
def trim(pygment_entry):
token, value = pygment_entry
if token is pygments.token.Token.Text and value.startswith(u"\n"):
return (token, value.rstrip(u" "))
return pygment_entry

if not pygments: # pragma: no cover
raise ImportError("no pygments")
pygments_list = list(pygments.lex(content, lexer))
pygments_list = map(trim, pygments_list)
return _join(pygments_list, (pygments.token.Token.Text, u"\n"))


Expand Down

0 comments on commit 717499a

Please sign in to comment.