mirror of
https://github.com/bugsink/bugsink.git
synced 2025-12-30 09:50:11 -06:00
Remove workaround for pygments empty newlines; there's a real solution
This commit is contained in:
@@ -19,20 +19,13 @@ def _split(joined, lengths):
|
||||
return result
|
||||
|
||||
|
||||
def noempty(lines):
|
||||
# if the line is empty, replace it with a space; this is needed to avoid pygments dropping empty lines (I've
|
||||
# obvserved this for leading empty lines, but the problem might be more general)
|
||||
# https://github.com/pygments/pygments/issues/2673
|
||||
return [" " if not line else line for line in lines]
|
||||
|
||||
|
||||
@register.filter
|
||||
def pygmentize(value):
|
||||
# first, get the actual code from the frame
|
||||
lengths = [len(value['pre_context']), 1, len(value['post_context'])]
|
||||
|
||||
code = "\n".join(noempty(value['pre_context']) + [value['context_line']] + noempty(value['post_context']))
|
||||
pygments_result = highlight(code, PythonLexer(), HtmlFormatter(nowrap=True))
|
||||
code = "\n".join(value['pre_context'] + [value['context_line']] + value['post_context'])
|
||||
pygments_result = highlight(code, PythonLexer(stripnl=False), HtmlFormatter(nowrap=True))
|
||||
lines = pygments_result.split('\n')[:-1] # remove the last empty line, which is a result of split()
|
||||
|
||||
assert len(lines) == sum(lengths), "%d != %d" % (len(lines), sum(lengths))
|
||||
|
||||
Reference in New Issue
Block a user