~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/highlight.py

  • Committer: Tres Seaver
  • Date: 2010-03-25 10:25:13 UTC
  • mto: This revision was merged to the branch mainline in revision 405.
  • Revision ID: tseaver@agendaless.com-20100325102513-imvok1jbu36cxg0t
Use 'Loggerhead' as the display name;  fix typos.

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, style=DEFAULT_PYGMENT_STYLE):
 
27
def highlight(path, text, encoding, 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
 
 
41
34
    try:
42
35
        lexer = guess_lexer_for_filename(path, text[:1024], encoding=encoding)
43
36
    except (ClassNotFound, ValueError):