##// END OF EJS Templates
highlight: Generate pygments style sheet dynamically...
Isaac Jurado -
r6485:93831941 default
parent child Browse files
Show More
@@ -15,10 +15,7 b' There is a single configuration option:'
15 [web]
15 [web]
16 pygments_style = <style>
16 pygments_style = <style>
17
17
18 The default is 'colorful'. If this is changed the corresponding CSS
18 The default is 'colorful'.
19 file should be re-generated by running
20
21 # pygmentize -f html -S <newstyle>
22
19
23 -- Adam Hupp <adam@hupp.org>
20 -- Adam Hupp <adam@hupp.org>
24 """
21 """
@@ -26,7 +23,7 b' file should be re-generated by running'
26 from mercurial import demandimport
23 from mercurial import demandimport
27 demandimport.ignore.extend(['pkgutil', 'pkg_resources', '__main__',])
24 demandimport.ignore.extend(['pkgutil', 'pkg_resources', '__main__',])
28
25
29 from mercurial.hgweb import webcommands, webutil
26 from mercurial.hgweb import webcommands, webutil, common
30 from mercurial import util
27 from mercurial import util
31 from mercurial.templatefilters import filters
28 from mercurial.templatefilters import filters
32
29
@@ -35,7 +32,7 b' from pygments.util import ClassNotFound'
35 from pygments.lexers import guess_lexer, guess_lexer_for_filename, TextLexer
32 from pygments.lexers import guess_lexer, guess_lexer_for_filename, TextLexer
36 from pygments.formatters import HtmlFormatter
33 from pygments.formatters import HtmlFormatter
37
34
38 SYNTAX_CSS = ('\n<link rel="stylesheet" href="#staticurl#highlight.css" '
35 SYNTAX_CSS = ('\n<link rel="stylesheet" href="{url}highlightcss" '
39 'type="text/css" />')
36 'type="text/css" />')
40
37
41 def pygmentize(field, fctx, style, tmpl):
38 def pygmentize(field, fctx, style, tmpl):
@@ -88,7 +85,16 b' def annotate_highlight(web, req, tmpl):'
88 pygmentize('annotateline', fctx, style, tmpl)
85 pygmentize('annotateline', fctx, style, tmpl)
89 return web_annotate(web, req, tmpl)
86 return web_annotate(web, req, tmpl)
90
87
88 def generate_css(web, req, tmpl):
89 pg_style = web.config('web', 'pygments_style', 'colorful')
90 fmter = HtmlFormatter(style = pg_style)
91 req.respond(common.HTTP_OK, 'text/css')
92 return ['/* pygments_style = %s */\n\n' % pg_style, fmter.get_style_defs('')]
93
94
91 # monkeypatch in the new version
95 # monkeypatch in the new version
92
96
93 webcommands._filerevision = filerevision_highlight
97 webcommands._filerevision = filerevision_highlight
94 webcommands.annotate = annotate_highlight
98 webcommands.annotate = annotate_highlight
99 webcommands.highlightcss = generate_css
100 webcommands.__all__.append('highlightcss')
@@ -5,6 +5,8 b''
5 cat <<EOF >> $HGRCPATH
5 cat <<EOF >> $HGRCPATH
6 [extensions]
6 [extensions]
7 hgext.highlight =
7 hgext.highlight =
8 [web]
9 pygments_style = friendly
8 EOF
10 EOF
9
11
10 hg init test
12 hg init test
@@ -24,6 +26,28 b' echo % hgweb fileannotate'
24 ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/get-with-headers.py') \
26 ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/get-with-headers.py') \
25 | sed "s/[0-9]* years ago/long ago/g"
27 | sed "s/[0-9]* years ago/long ago/g"
26
28
29 echo % hgweb highlightcss friendly
30 ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/highlightcss') \
31 | head -n 4
32
33 echo % errors encountered
34 cat errors.log
35 kill `cat hg.pid`
36
37 # Change the pygments style
38 cat > .hg/hgrc <<EOF
39 [web]
40 pygments_style = fruity
41 EOF
42
43 echo % hg serve again
44 hg serve -p $HGPORT -d -n test --pid-file=hg.pid -A access.log -E errors.log
45 cat hg.pid >> $DAEMON_PIDS
46
47 echo % hgweb highlightcss fruity
48 ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/highlightcss') \
49 | head -n 4
50
27 echo % errors encountered
51 echo % errors encountered
28 cat errors.log
52 cat errors.log
29
53
@@ -10,7 +10,7 b' 200 Script output follows'
10 <meta name="robots" content="index, nofollow" />
10 <meta name="robots" content="index, nofollow" />
11 <link rel="stylesheet" href="/static/style.css" type="text/css" />
11 <link rel="stylesheet" href="/static/style.css" type="text/css" />
12
12
13 <link rel="stylesheet" href="/static/highlight.css" type="text/css" />
13 <link rel="stylesheet" href="/highlightcss" type="text/css" />
14 <title>test:get-with-headers.py</title>
14 <title>test:get-with-headers.py</title>
15 </head>
15 </head>
16 <body>
16 <body>
@@ -72,7 +72,7 b' 200 Script output follows'
72 <meta name="robots" content="index, nofollow" />
72 <meta name="robots" content="index, nofollow" />
73 <link rel="stylesheet" href="/static/style.css" type="text/css" />
73 <link rel="stylesheet" href="/static/style.css" type="text/css" />
74
74
75 <link rel="stylesheet" href="/static/highlight.css" type="text/css" />
75 <link rel="stylesheet" href="/highlightcss" type="text/css" />
76 <title>test: get-with-headers.py annotate</title>
76 <title>test: get-with-headers.py annotate</title>
77 </head>
77 </head>
78 <body>
78 <body>
@@ -126,4 +126,16 b' 200 Script output follows'
126 </body>
126 </body>
127 </html>
127 </html>
128
128
129 % hgweb highlightcss friendly
130 200 Script output follows
131
132 /* pygments_style = friendly */
133
129 % errors encountered
134 % errors encountered
135 % hg serve again
136 % hgweb highlightcss fruity
137 200 Script output follows
138
139 /* pygments_style = fruity */
140
141 % errors encountered
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now