comparison hgext/highlight.py @ 6198:358cc9cf54db

highlight: guess by text when path name is ambiguous Although the docs claim that guess_lexer_for_filename will fall back to using file data, my ubuntu 7.10 pygments library seems to ignore the text argument. So call guess_lexer explicitly on failure.
author Brendan Cully <brendan@kublai.com>
date Fri, 29 Feb 2008 14:47:07 -0800
parents f6565f7d9489
children 0068809347d7
comparison
equal deleted inserted replaced
6197:f6565f7d9489 6198:358cc9cf54db
63 # To get multi-line strings right, we can't format line-by-line 63 # To get multi-line strings right, we can't format line-by-line
64 try: 64 try:
65 lexer = guess_lexer_for_filename(fctx.path(), text, 65 lexer = guess_lexer_for_filename(fctx.path(), text,
66 encoding=util._encoding) 66 encoding=util._encoding)
67 except ClassNotFound: 67 except ClassNotFound:
68 lexer = TextLexer(encoding=util._encoding) 68 try:
69 lexer = guess_lexer(text, encoding=util._encoding)
70 except ClassNotFound:
71 lexer = TextLexer(encoding=util._encoding)
69 72
70 formatter = HtmlFormatter(style=style, encoding=util._encoding) 73 formatter = HtmlFormatter(style=style, encoding=util._encoding)
71 74
72 colorized = highlight(text, lexer, formatter) 75 colorized = highlight(text, lexer, formatter)
73 # strip wrapping div 76 # strip wrapping div