comparison hgext/highlight/__init__.py @ 6938:ce94b3236ea4

highlight: split code to improve startup times
author Patrick Mezard <pmezard@gmail.com>
date Mon, 25 Aug 2008 23:04:56 +0200
parents
children d09e813b21e3
comparison
equal deleted inserted replaced
6937:3aa8ad0e03ba 6938:ce94b3236ea4
1 """a mercurial extension for syntax highlighting in hgweb
2
3 It depends on the pygments syntax highlighting library:
4 http://pygments.org/
5
6 To enable the extension add this to hgrc:
7
8 [extensions]
9 hgext.highlight =
10
11 There is a single configuration option:
12
13 [web]
14 pygments_style = <style>
15
16 The default is 'colorful'.
17
18 -- Adam Hupp <adam@hupp.org>
19 """
20
21 import highlight
22 from mercurial.hgweb import webcommands, webutil, common
23
24 web_filerevision = webcommands._filerevision
25 web_annotate = webcommands.annotate
26
27 def filerevision_highlight(web, tmpl, fctx):
28 style = web.config('web', 'pygments_style', 'colorful')
29 highlight.pygmentize('fileline', fctx, style, tmpl)
30 return web_filerevision(web, tmpl, fctx)
31
32 def annotate_highlight(web, req, tmpl):
33 fctx = webutil.filectx(web.repo, req)
34 style = web.config('web', 'pygments_style', 'colorful')
35 highlight.pygmentize('annotateline', fctx, style, tmpl)
36 return web_annotate(web, req, tmpl)
37
38 def generate_css(web, req, tmpl):
39 pg_style = web.config('web', 'pygments_style', 'colorful')
40 fmter = highlight.HtmlFormatter(style = pg_style)
41 req.respond(common.HTTP_OK, 'text/css')
42 return ['/* pygments_style = %s */\n\n' % pg_style, fmter.get_style_defs('')]
43
44
45 # monkeypatch in the new version
46
47 webcommands._filerevision = filerevision_highlight
48 webcommands.annotate = annotate_highlight
49 webcommands.highlightcss = generate_css
50 webcommands.__all__.append('highlightcss')