##// END OF EJS Templates
highlight: use reST syntax for literal block
Martin Geisler -
r9210:2667ca52 default
parent child Browse files
Show More
@@ -1,59 +1,59 b''
1 # highlight - syntax highlighting in hgweb, based on Pygments
1 # highlight - syntax highlighting in hgweb, based on Pygments
2 #
2 #
3 # Copyright 2008, 2009 Patrick Mezard <pmezard@gmail.com> and others
3 # Copyright 2008, 2009 Patrick Mezard <pmezard@gmail.com> and others
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2, incorporated herein by reference.
6 # GNU General Public License version 2, incorporated herein by reference.
7 #
7 #
8 # The original module was split in an interface and an implementation
8 # The original module was split in an interface and an implementation
9 # file to defer pygments loading and speedup extension setup.
9 # file to defer pygments loading and speedup extension setup.
10
10
11 """syntax highlighting for hgweb (requires Pygments)
11 """syntax highlighting for hgweb (requires Pygments)
12
12
13 It depends on the Pygments syntax highlighting library: http://pygments.org/
13 It depends on the Pygments syntax highlighting library: http://pygments.org/
14
14
15 There is a single configuration option:
15 There is a single configuration option::
16
16
17 [web]
17 [web]
18 pygments_style = <style>
18 pygments_style = <style>
19
19
20 The default is 'colorful'.
20 The default is 'colorful'.
21 """
21 """
22
22
23 import highlight
23 import highlight
24 from mercurial.hgweb import webcommands, webutil, common
24 from mercurial.hgweb import webcommands, webutil, common
25 from mercurial import extensions, encoding
25 from mercurial import extensions, encoding
26
26
27 def filerevision_highlight(orig, web, tmpl, fctx):
27 def filerevision_highlight(orig, web, tmpl, fctx):
28 mt = ''.join(tmpl('mimetype', encoding=encoding.encoding))
28 mt = ''.join(tmpl('mimetype', encoding=encoding.encoding))
29 # only pygmentize for mimetype containing 'html' so we both match
29 # only pygmentize for mimetype containing 'html' so we both match
30 # 'text/html' and possibly 'application/xhtml+xml' in the future
30 # 'text/html' and possibly 'application/xhtml+xml' in the future
31 # so that we don't have to touch the extension when the mimetype
31 # so that we don't have to touch the extension when the mimetype
32 # for a template changes; also hgweb optimizes the case that a
32 # for a template changes; also hgweb optimizes the case that a
33 # raw file is sent using rawfile() and doesn't call us, so we
33 # raw file is sent using rawfile() and doesn't call us, so we
34 # can't clash with the file's content-type here in case we
34 # can't clash with the file's content-type here in case we
35 # pygmentize a html file
35 # pygmentize a html file
36 if 'html' in mt:
36 if 'html' in mt:
37 style = web.config('web', 'pygments_style', 'colorful')
37 style = web.config('web', 'pygments_style', 'colorful')
38 highlight.pygmentize('fileline', fctx, style, tmpl)
38 highlight.pygmentize('fileline', fctx, style, tmpl)
39 return orig(web, tmpl, fctx)
39 return orig(web, tmpl, fctx)
40
40
41 def annotate_highlight(orig, web, req, tmpl):
41 def annotate_highlight(orig, web, req, tmpl):
42 mt = ''.join(tmpl('mimetype', encoding=encoding.encoding))
42 mt = ''.join(tmpl('mimetype', encoding=encoding.encoding))
43 if 'html' in mt:
43 if 'html' in mt:
44 fctx = webutil.filectx(web.repo, req)
44 fctx = webutil.filectx(web.repo, req)
45 style = web.config('web', 'pygments_style', 'colorful')
45 style = web.config('web', 'pygments_style', 'colorful')
46 highlight.pygmentize('annotateline', fctx, style, tmpl)
46 highlight.pygmentize('annotateline', fctx, style, tmpl)
47 return orig(web, req, tmpl)
47 return orig(web, req, tmpl)
48
48
49 def generate_css(web, req, tmpl):
49 def generate_css(web, req, tmpl):
50 pg_style = web.config('web', 'pygments_style', 'colorful')
50 pg_style = web.config('web', 'pygments_style', 'colorful')
51 fmter = highlight.HtmlFormatter(style = pg_style)
51 fmter = highlight.HtmlFormatter(style = pg_style)
52 req.respond(common.HTTP_OK, 'text/css')
52 req.respond(common.HTTP_OK, 'text/css')
53 return ['/* pygments_style = %s */\n\n' % pg_style, fmter.get_style_defs('')]
53 return ['/* pygments_style = %s */\n\n' % pg_style, fmter.get_style_defs('')]
54
54
55 # monkeypatch in the new version
55 # monkeypatch in the new version
56 extensions.wrapfunction(webcommands, '_filerevision', filerevision_highlight)
56 extensions.wrapfunction(webcommands, '_filerevision', filerevision_highlight)
57 extensions.wrapfunction(webcommands, 'annotate', annotate_highlight)
57 extensions.wrapfunction(webcommands, 'annotate', annotate_highlight)
58 webcommands.highlightcss = generate_css
58 webcommands.highlightcss = generate_css
59 webcommands.__all__.append('highlightcss')
59 webcommands.__all__.append('highlightcss')
General Comments 0
You need to be logged in to leave comments. Login now