##// 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 b' def pygments_format(filename, rawtext, f'
82 82 return highlight(rawtext, lexer, formatter)
83 83
84 84
85 def filerevision_pygments(self, fctx):
85 def filerevision_pygments(self, tmpl, fctx):
86 86 """Reimplement hgweb.filerevision to use syntax highlighting"""
87 filename = fctx.path()
87 f = fctx.path()
88 88
89 89 rawtext = fctx.data()
90 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 97 if util.binary(text):
95 98 mt = mt or 'application/octet-stream'
@@ -107,36 +110,35 b' def filerevision_pygments(self, fctx):'
107 110
108 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 114 forcetext=forcetext,
112 115 stripecount=self.stripecount,
113 116 style=style))
114 117
115 118 # override per-line template
116 self.t.cache['fileline'] = '#line#'
119 tmpl.cache['fileline'] = '#line#'
117 120
118 121 # append a <link ...> to the syntax highlighting css
119 old_header = ''.join(self.t('header'))
122 old_header = ''.join(tmpl('header'))
120 123 if SYNTAX_CSS not in old_header:
121 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",
125 file=filename,
126 path=hgweb_mod._up(filename), # fixme: make public
127 text=text_formatted,
128 raw=rawtext,
129 mimetype=mt,
130 rev=fctx.rev(),
131 node=hex(fctx.node()),
132 author=fctx.user(),
133 date=fctx.date(),
134 desc=fctx.description(),
135 parent=self.siblings(fctx.parents()),
136 child=self.siblings(fctx.children()),
137 rename=self.renamelink(fctx.filelog(),
138 fctx.filenode()),
139 permissions=fctx.manifest().flags(filename))
127 yield tmpl("filerevision",
128 file=f,
129 path=hgweb_mod._up(f), # fixme: make public
130 text=text_formatted,
131 raw=rawtext,
132 mimetype=mt,
133 rev=fctx.rev(),
134 node=hex(fctx.node()),
135 author=fctx.user(),
136 date=fctx.date(),
137 desc=fctx.description(),
138 parent=self.siblings(fctx.parents()),
139 child=self.siblings(fctx.children()),
140 rename=self.renamelink(fl, n),
141 permissions=fctx.manifest().flags(f))
140 142
141 143
142 144 # monkeypatch in the new version
General Comments 0
You need to be logged in to leave comments. Login now