Changeset 1801

Show
Ignore:
Timestamp:
11/18/08 16:21:33 (16 months ago)
Author:
JensDiemer
Message:

work a round for  http://dev.pocoo.org/projects/pygments/ticket/371

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid_project/PyLucid/system/hightlighter.py

    r1770 r1801  
    2727 
    2828try: 
     29    import pygments 
    2930    from pygments import lexers 
    3031    from pygments.formatters import HtmlFormatter 
    3132    from pygments import highlight 
    3233    PYGMENTS_AVAILABLE = True 
    33 except ImportError: 
     34except ImportError, err: 
    3435    PYGMENTS_AVAILABLE = False 
     36    import_error = err 
    3537 
    3638HTML = ( 
     
    4042    '</fieldset>\n' 
    4143) 
    42 CSSCLASS = u"pygments" 
     44# There exist a bug in pygments, if cssclass is given as unicode: 
     45# http://dev.pocoo.org/projects/pygments/ticket/371 
     46CSSCLASS = "pygments" 
    4347 
    4448def make_html(sourcecode, source_type): 
     
    5458    formatter = HtmlFormatter( 
    5559        linenos=True, encoding="utf-8", style='colorful', 
     60        outencoding = "utf-8", 
    5661        cssclass = CSSCLASS, 
    5762    ) 
     
    8590 
    8691    out_object = SimpleStringIO() 
    87     highlight(sourcecode, lexer, formatter, out_object) 
    88     html = out_object.getvalue() 
     92    try: 
     93        highlight(sourcecode, lexer, formatter, out_object) 
     94    except Exception, err: 
     95        if settings.DEBUG: 
     96            raise 
     97        html = no_hightlight(sourcecode) 
     98        lexer_name += " (Error: %s)" % err 
     99    else: 
     100        html = out_object.getvalue() 
    89101 
    90     # If there is e.g. html code with django tags, we must escape this: 
    91     html = escape_django_tags(html) 
     102        # If there is e.g. html code with django tags, we must escape this: 
     103        html = escape_django_tags(html) 
     104        html = html.decode("utf-8") 
    92105 
    93106    return html, lexer_name