Ticket #387: reports.diff

File reports.diff, 1.1 KB (added by desai, 15 years ago)
  • src/lib/Server/Reports/reports/templatetags/syntax_coloring.py

     
    11from django import template 
    22 
     3register = template.Library() 
     4 
    35try: 
    46    from pygments import highlight 
    57    from pygments.lexers import get_lexer_by_name 
    68    from pygments.formatters import HtmlFormatter 
    79    colorize = True 
     10 
    811except: 
    912    colorize = False 
    10      
    11 register = template.Library() 
    1213 
    1314def syntaxhilight(value, arg="diff"): 
    14     '''Returns a syntax-hilighted version of Code; requires code and language arguments''' 
    15     lexer = get_lexer_by_name(arg) 
     15    '''Returns a syntax-hilighted version of Code; requires code/language arguments''' 
    1616    if colorize: 
    1717        try: 
     18            lexer = get_lexer_by_name(arg) 
    1819            return highlight(value, lexer, HtmlFormatter()) 
    1920        except: 
    2021            return value 
    2122    else: 
    2223        return value 
    2324 
    24  
    2525register.filter('syntaxhilight', syntaxhilight)