Changeset 1801
- Timestamp:
- 11/18/08 16:21:33 (16 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid_project/PyLucid/system/hightlighter.py
r1770 r1801 27 27 28 28 try: 29 import pygments 29 30 from pygments import lexers 30 31 from pygments.formatters import HtmlFormatter 31 32 from pygments import highlight 32 33 PYGMENTS_AVAILABLE = True 33 except ImportError :34 except ImportError, err: 34 35 PYGMENTS_AVAILABLE = False 36 import_error = err 35 37 36 38 HTML = ( … … 40 42 '</fieldset>\n' 41 43 ) 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 46 CSSCLASS = "pygments" 43 47 44 48 def make_html(sourcecode, source_type): … … 54 58 formatter = HtmlFormatter( 55 59 linenos=True, encoding="utf-8", style='colorful', 60 outencoding = "utf-8", 56 61 cssclass = CSSCLASS, 57 62 ) … … 85 90 86 91 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() 89 101 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") 92 105 93 106 return html, lexer_name