# HG changeset patch # User Christian Ebert # Date 1197467099 -3600 # Node ID fe38b0a3a92873d9e96990e7396c3a75df0403e8 # Parent 831e34e17f4f33ffc5073aa42d1bb81eb61885e2 highlight: pass encoding to lexers and formatter Try to avoid UnicodeDecodeError by: - encoding to local - passing util._encoding as lexer input encoding - passing hgweb.encoding as formatter output encoding diff -r 831e34e17f4f -r fe38b0a3a928 hgext/highlight.py --- a/hgext/highlight.py Wed Dec 12 14:36:34 2007 +0100 +++ b/hgext/highlight.py Wed Dec 12 14:44:59 2007 +0100 @@ -66,19 +66,22 @@ yield 0, "" -def pygments_format(filename, rawtext, forcetext, stripecount, style): +def pygments_format(filename, rawtext, forcetext, encoding, + stripecount, style): + etext = util.tolocal(rawtext) if not forcetext: try: - lexer = guess_lexer_for_filename(filename, rawtext) + lexer = guess_lexer_for_filename(filename, etext, + encoding=util._encoding) except ClassNotFound: - lexer = TextLexer() + lexer = TextLexer(encoding=util._encoding) else: - lexer = TextLexer() + lexer = TextLexer(encoding=util._encoding) formatter = StripedHtmlFormatter(stripecount, style=style, - linenos='inline') + linenos='inline', encoding=encoding) - return highlight(rawtext, lexer, formatter) + return highlight(etext, lexer, formatter) def filerevision_pygments(self, tmpl, fctx): @@ -109,7 +112,7 @@ style = self.config("web", "pygments_style", "colorful") - text_formatted = lines(pygments_format(f, text, forcetext, + text_formatted = lines(pygments_format(f, text, forcetext, self.encoding, self.stripecount, style)) # override per-line template