comparison hgext/highlight.py @ 6662:22c303a514f8

Truncate input to 1K when using pygments guess_lexer. This function appears to be exponential with input length.
author Brendan Cully <brendan@kublai.com>
date Thu, 12 Jun 2008 00:11:09 -0700
parents c30849d4c8ba
children 73f49bef13ad
comparison
equal deleted inserted replaced
6651:7f0dd352fb4d 6662:22c303a514f8
55 return 55 return
56 56
57 style = self.config("web", "pygments_style", "colorful") 57 style = self.config("web", "pygments_style", "colorful")
58 # To get multi-line strings right, we can't format line-by-line 58 # To get multi-line strings right, we can't format line-by-line
59 try: 59 try:
60 lexer = guess_lexer_for_filename(fctx.path(), text, 60 lexer = guess_lexer_for_filename(fctx.path(), text[:1024],
61 encoding=util._encoding) 61 encoding=util._encoding)
62 except (ClassNotFound, ValueError): 62 except (ClassNotFound, ValueError):
63 try: 63 try:
64 lexer = guess_lexer(text, encoding=util._encoding) 64 lexer = guess_lexer(text[:1024], encoding=util._encoding)
65 except (ClassNotFound, ValueError): 65 except (ClassNotFound, ValueError):
66 lexer = TextLexer(encoding=util._encoding) 66 lexer = TextLexer(encoding=util._encoding)
67 67
68 formatter = HtmlFormatter(style=style, encoding=util._encoding) 68 formatter = HtmlFormatter(style=style, encoding=util._encoding)
69 69