# HG changeset patch # User Brendan Cully # Date 2008-02-29 22:47:07 # Node ID 358cc9cf54dbc0d7a37cf9d7800ddd8307a75ce6 # Parent f6565f7d9489a7ae65ad81e3b38c130bf44091ba 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. diff --git a/hgext/highlight.py b/hgext/highlight.py --- a/hgext/highlight.py +++ b/hgext/highlight.py @@ -65,7 +65,10 @@ def pygmentize(self, tmpl, fctx, field): lexer = guess_lexer_for_filename(fctx.path(), text, encoding=util._encoding) except ClassNotFound: - lexer = TextLexer(encoding=util._encoding) + try: + lexer = guess_lexer(text, encoding=util._encoding) + except ClassNotFound: + lexer = TextLexer(encoding=util._encoding) formatter = HtmlFormatter(style=style, encoding=util._encoding)