Show More
@@ -0,0 +1,50 b'' | |||
|
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') |
@@ -1,27 +1,11 b'' | |||
|
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 | """ | |
|
1 | # highlight extension implementation file | |
|
2 | # | |
|
3 | # The original module was split in an interface and an implementation | |
|
4 | # file to defer pygments loading and speedup extension setup. | |
|
20 | 5 | |
|
21 | 6 | from mercurial import demandimport |
|
22 | 7 | demandimport.ignore.extend(['pkgutil', 'pkg_resources', '__main__',]) |
|
23 | 8 | |
|
24 | from mercurial.hgweb import webcommands, webutil, common | |
|
25 | 9 | from mercurial import util |
|
26 | 10 | from mercurial.templatefilters import filters |
|
27 | 11 | |
@@ -68,31 +52,3 b' def pygmentize(field, fctx, style, tmpl)' | |||
|
68 | 52 | oldl = tmpl.cache[field] |
|
69 | 53 | newl = oldl.replace('line|escape', 'line|colorize') |
|
70 | 54 | tmpl.cache[field] = newl |
|
71 | ||
|
72 | web_filerevision = webcommands._filerevision | |
|
73 | web_annotate = webcommands.annotate | |
|
74 | ||
|
75 | def filerevision_highlight(web, tmpl, fctx): | |
|
76 | style = web.config('web', 'pygments_style', 'colorful') | |
|
77 | pygmentize('fileline', fctx, style, tmpl) | |
|
78 | return web_filerevision(web, tmpl, fctx) | |
|
79 | ||
|
80 | def annotate_highlight(web, req, tmpl): | |
|
81 | fctx = webutil.filectx(web.repo, req) | |
|
82 | style = web.config('web', 'pygments_style', 'colorful') | |
|
83 | pygmentize('annotateline', fctx, style, tmpl) | |
|
84 | return web_annotate(web, req, tmpl) | |
|
85 | ||
|
86 | def generate_css(web, req, tmpl): | |
|
87 | pg_style = web.config('web', 'pygments_style', 'colorful') | |
|
88 | fmter = HtmlFormatter(style = pg_style) | |
|
89 | req.respond(common.HTTP_OK, 'text/css') | |
|
90 | return ['/* pygments_style = %s */\n\n' % pg_style, fmter.get_style_defs('')] | |
|
91 | ||
|
92 | ||
|
93 | # monkeypatch in the new version | |
|
94 | ||
|
95 | webcommands._filerevision = filerevision_highlight | |
|
96 | webcommands.annotate = annotate_highlight | |
|
97 | webcommands.highlightcss = generate_css | |
|
98 | webcommands.__all__.append('highlightcss') |
@@ -98,7 +98,8 b' ext_modules=[' | |||
|
98 | 98 | Extension('mercurial.parsers', ['mercurial/parsers.c']), |
|
99 | 99 | ] |
|
100 | 100 | |
|
101 |
packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert' |
|
|
101 | packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert', | |
|
102 | 'hgext.highlight'] | |
|
102 | 103 | |
|
103 | 104 | try: |
|
104 | 105 | import posix |
General Comments 0
You need to be logged in to leave comments.
Login now