Mercurial > hg
comparison hgext/highlight.py @ 5991:31726c27e40e
highlight: update according to latest hgweb_mod changes
Also move encoding workaround completely into non binary condition.
author | Christian Ebert <blacktrash@gmx.net> |
---|---|
date | Thu, 31 Jan 2008 13:57:48 +0100 |
parents | 5957c7b5894a |
children | 2344da8eb9b4 |
comparison
equal
deleted
inserted
replaced
5990:71d675f4b1f8 | 5991:31726c27e40e |
---|---|
83 | 83 |
84 | 84 |
85 def filerevision_pygments(self, tmpl, fctx): | 85 def filerevision_pygments(self, tmpl, fctx): |
86 """Reimplement hgweb.filerevision to use syntax highlighting""" | 86 """Reimplement hgweb.filerevision to use syntax highlighting""" |
87 f = fctx.path() | 87 f = fctx.path() |
88 | 88 text = fctx.data() |
89 rawtext = fctx.data() | |
90 text = rawtext | |
91 | |
92 fl = fctx.filelog() | 89 fl = fctx.filelog() |
93 n = fctx.filenode() | 90 n = fctx.filenode() |
94 | 91 |
95 mt = mimetypes.guess_type(f)[0] | |
96 | |
97 # we always want hgweb.encoding | |
98 util._encoding = self.encoding | |
99 | |
100 if util.binary(text): | 92 if util.binary(text): |
101 mt = mt or 'application/octet-stream' | 93 mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' |
102 text = "(binary:%s)" % mt | 94 text = "(binary:%s)" % mt |
103 | |
104 # don't parse (binary:...) as anything | 95 # don't parse (binary:...) as anything |
105 forcetext = True | 96 forcetext = True |
106 else: | 97 else: |
107 mt = mt or 'text/plain' | |
108 | |
109 # encode to hgweb.encoding for lexers and formatter | 98 # encode to hgweb.encoding for lexers and formatter |
99 util._encoding = self.encoding | |
110 text = util.tolocal(text) | 100 text = util.tolocal(text) |
111 forcetext = False | 101 forcetext = False |
112 | 102 |
113 def lines(text): | 103 def lines(text): |
114 for line in text.splitlines(True): | 104 for line in text.splitlines(True): |
126 old_header = ''.join(tmpl('header')) | 116 old_header = ''.join(tmpl('header')) |
127 if SYNTAX_CSS not in old_header: | 117 if SYNTAX_CSS not in old_header: |
128 new_header = old_header + SYNTAX_CSS | 118 new_header = old_header + SYNTAX_CSS |
129 tmpl.cache['header'] = new_header | 119 tmpl.cache['header'] = new_header |
130 | 120 |
131 yield tmpl("filerevision", | 121 return tmpl("filerevision", |
132 file=f, | 122 file=f, |
133 path=hgweb_mod._up(f), # fixme: make public | 123 path=hgweb_mod._up(f), # fixme: make public |
134 text=text_formatted, | 124 text=text_formatted, |
135 raw=rawtext, | |
136 mimetype=mt, | |
137 rev=fctx.rev(), | 125 rev=fctx.rev(), |
138 node=hex(fctx.node()), | 126 node=hex(fctx.node()), |
139 author=fctx.user(), | 127 author=fctx.user(), |
140 date=fctx.date(), | 128 date=fctx.date(), |
141 desc=fctx.description(), | 129 desc=fctx.description(), |