diff --git a/hgext/highlight.py b/hgext/highlight.py --- a/hgext/highlight.py +++ b/hgext/highlight.py @@ -66,19 +66,22 @@ class StripedHtmlFormatter(HtmlFormatter 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 @@ def filerevision_pygments(self, tmpl, fc 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