##// END OF EJS Templates
highlight: fix more tracebacks by forcing util._encoding to hgweb.encoding...
Christian Ebert -
r5748:5957c7b5 default
parent child Browse files
Show More
@@ -66,12 +66,10 b' class StripedHtmlFormatter(HtmlFormatter'
66 yield 0, "</div>"
66 yield 0, "</div>"
67
67
68
68
69 def pygments_format(filename, rawtext, forcetext, encoding,
69 def pygments_format(filename, text, forcetext, stripecount, style):
70 stripecount, style):
71 etext = util.tolocal(rawtext)
72 if not forcetext:
70 if not forcetext:
73 try:
71 try:
74 lexer = guess_lexer_for_filename(filename, etext,
72 lexer = guess_lexer_for_filename(filename, text,
75 encoding=util._encoding)
73 encoding=util._encoding)
76 except ClassNotFound:
74 except ClassNotFound:
77 lexer = TextLexer(encoding=util._encoding)
75 lexer = TextLexer(encoding=util._encoding)
@@ -79,9 +77,9 b' def pygments_format(filename, rawtext, f'
79 lexer = TextLexer(encoding=util._encoding)
77 lexer = TextLexer(encoding=util._encoding)
80
78
81 formatter = StripedHtmlFormatter(stripecount, style=style,
79 formatter = StripedHtmlFormatter(stripecount, style=style,
82 linenos='inline', encoding=encoding)
80 linenos='inline', encoding=util._encoding)
83
81
84 return highlight(etext, lexer, formatter)
82 return highlight(text, lexer, formatter)
85
83
86
84
87 def filerevision_pygments(self, tmpl, fctx):
85 def filerevision_pygments(self, tmpl, fctx):
@@ -96,6 +94,9 b' def filerevision_pygments(self, tmpl, fc'
96
94
97 mt = mimetypes.guess_type(f)[0]
95 mt = mimetypes.guess_type(f)[0]
98
96
97 # we always want hgweb.encoding
98 util._encoding = self.encoding
99
99 if util.binary(text):
100 if util.binary(text):
100 mt = mt or 'application/octet-stream'
101 mt = mt or 'application/octet-stream'
101 text = "(binary:%s)" % mt
102 text = "(binary:%s)" % mt
@@ -104,6 +105,9 b' def filerevision_pygments(self, tmpl, fc'
104 forcetext = True
105 forcetext = True
105 else:
106 else:
106 mt = mt or 'text/plain'
107 mt = mt or 'text/plain'
108
109 # encode to hgweb.encoding for lexers and formatter
110 text = util.tolocal(text)
107 forcetext = False
111 forcetext = False
108
112
109 def lines(text):
113 def lines(text):
@@ -112,7 +116,7 b' def filerevision_pygments(self, tmpl, fc'
112
116
113 style = self.config("web", "pygments_style", "colorful")
117 style = self.config("web", "pygments_style", "colorful")
114
118
115 text_formatted = lines(pygments_format(f, text, forcetext, self.encoding,
119 text_formatted = lines(pygments_format(f, text, forcetext,
116 self.stripecount, style))
120 self.stripecount, style))
117
121
118 # override per-line template
122 # override per-line template
General Comments 0
You need to be logged in to leave comments. Login now