Mercurial > hg
comparison hgext/highlight.py @ 5616:88ca3e0fb6e5
highlight: adapt to hgweb_mode refactoring
author | Christian Ebert <blacktrash@gmx.net> |
---|---|
date | Wed, 05 Dec 2007 12:48:33 +0100 |
parents | 6cf7d7fe7d3d |
children | 831e34e17f4f |
comparison
equal
deleted
inserted
replaced
5615:ce383c80a177 | 5616:88ca3e0fb6e5 |
---|---|
80 linenos='inline') | 80 linenos='inline') |
81 | 81 |
82 return highlight(rawtext, lexer, formatter) | 82 return highlight(rawtext, lexer, formatter) |
83 | 83 |
84 | 84 |
85 def filerevision_pygments(self, 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 filename = fctx.path() | 87 f = fctx.path() |
88 | 88 |
89 rawtext = fctx.data() | 89 rawtext = fctx.data() |
90 text = rawtext | 90 text = rawtext |
91 | 91 |
92 mt = mimetypes.guess_type(filename)[0] | 92 fl = fctx.filelog() |
93 n = fctx.filenode() | |
94 | |
95 mt = mimetypes.guess_type(f)[0] | |
93 | 96 |
94 if util.binary(text): | 97 if util.binary(text): |
95 mt = mt or 'application/octet-stream' | 98 mt = mt or 'application/octet-stream' |
96 text = "(binary:%s)" % mt | 99 text = "(binary:%s)" % mt |
97 | 100 |
105 for line in text.splitlines(True): | 108 for line in text.splitlines(True): |
106 yield {"line": line} | 109 yield {"line": line} |
107 | 110 |
108 style = self.config("web", "pygments_style", "colorful") | 111 style = self.config("web", "pygments_style", "colorful") |
109 | 112 |
110 text_formatted = lines(pygments_format(filename, text, | 113 text_formatted = lines(pygments_format(f, text, |
111 forcetext=forcetext, | 114 forcetext=forcetext, |
112 stripecount=self.stripecount, | 115 stripecount=self.stripecount, |
113 style=style)) | 116 style=style)) |
114 | 117 |
115 # override per-line template | 118 # override per-line template |
116 self.t.cache['fileline'] = '#line#' | 119 tmpl.cache['fileline'] = '#line#' |
117 | 120 |
118 # append a <link ...> to the syntax highlighting css | 121 # append a <link ...> to the syntax highlighting css |
119 old_header = ''.join(self.t('header')) | 122 old_header = ''.join(tmpl('header')) |
120 if SYNTAX_CSS not in old_header: | 123 if SYNTAX_CSS not in old_header: |
121 new_header = old_header + SYNTAX_CSS | 124 new_header = old_header + SYNTAX_CSS |
122 self.t.cache['header'] = new_header | 125 tmpl.cache['header'] = new_header |
123 | 126 |
124 yield self.t("filerevision", | 127 yield tmpl("filerevision", |
125 file=filename, | 128 file=f, |
126 path=hgweb_mod._up(filename), # fixme: make public | 129 path=hgweb_mod._up(f), # fixme: make public |
127 text=text_formatted, | 130 text=text_formatted, |
128 raw=rawtext, | 131 raw=rawtext, |
129 mimetype=mt, | 132 mimetype=mt, |
130 rev=fctx.rev(), | 133 rev=fctx.rev(), |
131 node=hex(fctx.node()), | 134 node=hex(fctx.node()), |
132 author=fctx.user(), | 135 author=fctx.user(), |
133 date=fctx.date(), | 136 date=fctx.date(), |
134 desc=fctx.description(), | 137 desc=fctx.description(), |
135 parent=self.siblings(fctx.parents()), | 138 parent=self.siblings(fctx.parents()), |
136 child=self.siblings(fctx.children()), | 139 child=self.siblings(fctx.children()), |
137 rename=self.renamelink(fctx.filelog(), | 140 rename=self.renamelink(fl, n), |
138 fctx.filenode()), | 141 permissions=fctx.manifest().flags(f)) |
139 permissions=fctx.manifest().flags(filename)) | |
140 | 142 |
141 | 143 |
142 # monkeypatch in the new version | 144 # monkeypatch in the new version |
143 # should be safer than overriding the method in a derived class | 145 # should be safer than overriding the method in a derived class |
144 # and then patching the class | 146 # and then patching the class |