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, |
61 encoding=util._encoding) |
61 encoding=util._encoding) |
62 except ClassNotFound: |
62 except (ClassNotFound, ValueError): |
63 try: |
63 try: |
64 lexer = guess_lexer(text, encoding=util._encoding) |
64 lexer = guess_lexer(text, encoding=util._encoding) |
65 except ClassNotFound: |
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 |
70 colorized = highlight(text, lexer, formatter) |
70 colorized = highlight(text, lexer, formatter) |