comparison hgext/highlight.py @ 6664:1e3c1f010808

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 5c1bb5750558
children 73f49bef13ad
comparison
equal deleted inserted replaced
6663:d8ae6a3a1833 6664:1e3c1f010808
47 if util.binary(text): 47 if util.binary(text):
48 return 48 return
49 49
50 # To get multi-line strings right, we can't format line-by-line 50 # To get multi-line strings right, we can't format line-by-line
51 try: 51 try:
52 lexer = guess_lexer_for_filename(fctx.path(), text, 52 lexer = guess_lexer_for_filename(fctx.path(), text[:1024],
53 encoding=util._encoding) 53 encoding=util._encoding)
54 except (ClassNotFound, ValueError): 54 except (ClassNotFound, ValueError):
55 try: 55 try:
56 lexer = guess_lexer(text, encoding=util._encoding) 56 lexer = guess_lexer(text[:1024], encoding=util._encoding)
57 except (ClassNotFound, ValueError): 57 except (ClassNotFound, ValueError):
58 lexer = TextLexer(encoding=util._encoding) 58 lexer = TextLexer(encoding=util._encoding)
59 59
60 formatter = HtmlFormatter(style=style, encoding=util._encoding) 60 formatter = HtmlFormatter(style=style, encoding=util._encoding)
61 61