~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/highlight.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-30 10:27:53 UTC
  • mto: (389.2.2 pep8-2009-10)
  • mto: This revision was merged to the branch mainline in revision 392.
  • Revision ID: mnordhoff@mattnordhoff.com-20090430102753-k0fe9v60gw0at3py
Whitespace tweak to profile.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
DEFAULT_PYGMENT_STYLE = 'colorful'
25
25
 
26
26
 
27
 
def highlight(path, text, encoding, style=DEFAULT_PYGMENT_STYLE):
 
27
def highlight(path, text, style=DEFAULT_PYGMENT_STYLE):
28
28
    """
29
29
    Returns a list of highlighted (i.e. HTML formatted) strings.
30
30
    """
31
31
 
32
32
    formatter = HtmlFormatter(style=style, nowrap=True, classprefix='pyg-')
33
33
 
 
34
    encoding = 'utf-8'
 
35
    try:
 
36
        text = text.decode(encoding)
 
37
    except UnicodeDecodeError:
 
38
        encoding = 'iso-8859-15'
 
39
        text = text.decode(encoding)
 
40
 
34
41
    try:
35
42
        lexer = guess_lexer_for_filename(path, text[:1024], encoding=encoding)
36
43
    except (ClassNotFound, ValueError):