From aca96e7dc93a509fd49548779cfd61a76b1960ed Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Fri, 29 Mar 2024 18:35:43 +0100 Subject: [PATCH] Remove workaround for pygments empty newlines; there's a real solution --- theme/templatetags/issues.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/theme/templatetags/issues.py b/theme/templatetags/issues.py index 89af0eb..21c3a60 100644 --- a/theme/templatetags/issues.py +++ b/theme/templatetags/issues.py @@ -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))