Skip to content

Commit

Permalink
Highlight diff output (#481)
Browse files Browse the repository at this point in the history
* Highlight diff output

The detection of diff content is a bit basic, but seems to work good enough for now.
  • Loading branch information
helmo authored Feb 11, 2023
1 parent 450c3e0 commit 94a7a4f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ara/ui/templatetags/pygments_highlights.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django import template
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import JsonLexer, YamlLexer
from pygments.lexers import DiffLexer, JsonLexer, YamlLexer
from pygments.lexers.special import TextLexer

register = template.Library()
Expand Down Expand Up @@ -38,7 +38,10 @@ def format_data(data):
data = json.dumps(json.loads(data), indent=4, sort_keys=True)
lexer = JsonLexer()
except (ValueError, TypeError):
lexer = TextLexer()
if data.startswith("---"):
lexer = DiffLexer()
else:
lexer = TextLexer()
elif isinstance(data, dict) or isinstance(data, list):
data = json.dumps(data, indent=4, sort_keys=True)
lexer = JsonLexer()
Expand Down

0 comments on commit 94a7a4f

Please sign in to comment.