Skip to content

Commit

Permalink
1.6.1dev: prevent uses of unnecessary lineno styles from Pygments 2.7…
Browse files Browse the repository at this point in the history
….0+ (closes #13866)

git-svn-id: http://trac.edgewall.org/intertrac/log:/branches/1.6-stable@17877 af82e41b-90c4-0310-8c96-b1721e28e2e2
  • Loading branch information
jomae committed Feb 5, 2025
1 parent 716c02a commit 528870b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions trac/mimeview/pygments.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@
__all__ = ['PygmentsRenderer']


if hasattr(HtmlFormatter, 'get_background_style_defs') and \
hasattr(HtmlFormatter, 'get_token_style_defs'):
def _get_style_defs(style, arg):
lines = []
formatter = HtmlFormatter(style=style)
lines.extend(formatter.get_background_style_defs(arg))
lines.extend(formatter.get_token_style_defs(arg))
return '\n'.join(lines)
else:
def _get_style_defs(style, arg):
formatter = HtmlFormatter(style=style)
return formatter.get_style_defs(arg)


class PygmentsRenderer(Component):
"""HTML renderer for syntax highlighting based on Pygments."""

Expand Down Expand Up @@ -186,8 +200,7 @@ def process_request(self, req):
req.end_headers()
return

formatter = HtmlFormatter(style=style_cls)
content = formatter.get_style_defs(['div.code pre', 'table.code td'])
content = _get_style_defs(style_cls, ['div.code pre', 'table.code td'])
content = content.encode('utf-8')

req.send_response(200)
Expand Down

0 comments on commit 528870b

Please sign in to comment.