##// END OF EJS Templates
highlight: adapt to hgweb_mode refactoring
Christian Ebert -
r5616:88ca3e0f default
parent child Browse files
Show More
@@ -82,14 +82,17 def pygments_format(filename, rawtext, f
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'
@@ -107,23 +110,23 def filerevision_pygments(self, fctx):
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,
@@ -134,9 +137,8 def filerevision_pygments(self, fctx):
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
General Comments 0
You need to be logged in to leave comments. Login now