diff --git a/hgext/highlight.py b/hgext/highlight.py
index f6565f7d9489a7ae65ad81e3b38c130bf44091ba_aGdleHQvaGlnaGxpZ2h0LnB5..358cc9cf54dbc0d7a37cf9d7800ddd8307a75ce6_aGdleHQvaGlnaGxpZ2h0LnB5 100644
--- a/hgext/highlight.py
+++ b/hgext/highlight.py
@@ -65,7 +65,10 @@
         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)