##// END OF EJS Templates
highlight: fix encoding issues to enable Py3 compatibility...
Connor Sheehan -
r43193:a7abc608 default
parent child Browse files
Show More
@@ -296,6 +296,7 test-hgweb.t
296 test-hgwebdir-paths.py
296 test-hgwebdir-paths.py
297 test-hgwebdir.t
297 test-hgwebdir.t
298 test-hgwebdirsym.t
298 test-hgwebdirsym.t
299 test-highlight.t
299 test-histedit-arguments.t
300 test-histedit-arguments.t
300 test-histedit-base.t
301 test-histedit-base.t
301 test-histedit-bookmark-motion.t
302 test-histedit-bookmark-motion.t
@@ -36,6 +36,7 from mercurial.hgweb import (
36
36
37 from mercurial import (
37 from mercurial import (
38 extensions,
38 extensions,
39 pycompat,
39 )
40 )
40
41
41 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
42 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
@@ -79,11 +80,12 def annotate_highlight(orig, web):
79
80
80 def generate_css(web):
81 def generate_css(web):
81 pg_style = web.config('web', 'pygments_style', 'colorful')
82 pg_style = web.config('web', 'pygments_style', 'colorful')
82 fmter = highlight.HtmlFormatter(style=pg_style)
83 fmter = highlight.HtmlFormatter(style=pycompat.sysstr(pg_style))
83 web.res.headers['Content-Type'] = 'text/css'
84 web.res.headers['Content-Type'] = 'text/css'
85 style_defs = fmter.get_style_defs(pycompat.sysstr(''))
84 web.res.setbodybytes(''.join([
86 web.res.setbodybytes(''.join([
85 '/* pygments_style = %s */\n\n' % pg_style,
87 '/* pygments_style = %s */\n\n' % pg_style,
86 fmter.get_style_defs(''),
88 pycompat.bytestr(style_defs),
87 ]))
89 ]))
88 return web.res.sendresponse()
90 return web.res.sendresponse()
89
91
@@ -15,6 +15,7 demandimport.IGNORES.update(['pkgutil',
15
15
16 from mercurial import (
16 from mercurial import (
17 encoding,
17 encoding,
18 pycompat,
18 )
19 )
19
20
20 from mercurial.utils import (
21 from mercurial.utils import (
@@ -61,11 +62,12 def pygmentize(field, fctx, style, tmpl,
61
62
62 # Pygments is best used with Unicode strings:
63 # Pygments is best used with Unicode strings:
63 # <http://pygments.org/docs/unicode/>
64 # <http://pygments.org/docs/unicode/>
64 text = text.decode(encoding.encoding, 'replace')
65 text = text.decode(pycompat.sysstr(encoding.encoding), 'replace')
65
66
66 # To get multi-line strings right, we can't format line-by-line
67 # To get multi-line strings right, we can't format line-by-line
67 try:
68 try:
68 lexer = guess_lexer_for_filename(fctx.path(), text[:1024],
69 path = pycompat.sysstr(fctx.path())
70 lexer = guess_lexer_for_filename(path, text[:1024],
69 stripnl=False)
71 stripnl=False)
70 except (ClassNotFound, ValueError):
72 except (ClassNotFound, ValueError):
71 # guess_lexer will return a lexer if *any* lexer matches. There is
73 # guess_lexer will return a lexer if *any* lexer matches. There is
@@ -84,10 +86,10 def pygmentize(field, fctx, style, tmpl,
84 if isinstance(lexer, TextLexer):
86 if isinstance(lexer, TextLexer):
85 return
87 return
86
88
87 formatter = HtmlFormatter(nowrap=True, style=style)
89 formatter = HtmlFormatter(nowrap=True, style=pycompat.sysstr(style))
88
90
89 colorized = highlight(text, lexer, formatter)
91 colorized = highlight(text, lexer, formatter)
90 coloriter = (s.encode(encoding.encoding, 'replace')
92 coloriter = (s.encode(pycompat.sysstr(encoding.encoding), 'replace')
91 for s in colorized.splitlines())
93 for s in colorized.splitlines())
92
94
93 tmpl._filters['colorize'] = lambda x: next(coloriter)
95 tmpl._filters['colorize'] = lambda x: next(coloriter)
General Comments 0
You need to be logged in to leave comments. Login now