Show More
@@ -13,23 +13,32 b'' | |||||
13 | It depends on the Pygments syntax highlighting library: |
|
13 | It depends on the Pygments syntax highlighting library: | |
14 | http://pygments.org/ |
|
14 | http://pygments.org/ | |
15 |
|
15 | |||
16 |
There |
|
16 | There are two configuration options:: | |
17 |
|
17 | |||
18 | [web] |
|
18 | [web] | |
19 | pygments_style = <style> |
|
19 | pygments_style = <style> (default: colorful) | |
20 |
|
20 | highlightfiles = <fileset> (default: size('<5M')) | ||
21 | The default is 'colorful'. |
|
|||
22 | """ |
|
21 | """ | |
23 |
|
22 | |||
24 | import highlight |
|
23 | import highlight | |
25 | from mercurial.hgweb import webcommands, webutil, common |
|
24 | from mercurial.hgweb import webcommands, webutil, common | |
26 | from mercurial import extensions, encoding |
|
25 | from mercurial import extensions, encoding, fileset | |
27 | # Note for extension authors: ONLY specify testedwith = 'internal' for |
|
26 | # Note for extension authors: ONLY specify testedwith = 'internal' for | |
28 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
|
27 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | |
29 | # be specifying the version(s) of Mercurial they are tested with, or |
|
28 | # be specifying the version(s) of Mercurial they are tested with, or | |
30 | # leave the attribute unspecified. |
|
29 | # leave the attribute unspecified. | |
31 | testedwith = 'internal' |
|
30 | testedwith = 'internal' | |
32 |
|
31 | |||
|
32 | def checkfctx(fctx, expr): | |||
|
33 | ctx = fctx.changectx() | |||
|
34 | tree = fileset.parse(expr) | |||
|
35 | mctx = fileset.matchctx(ctx, subset=[fctx.path()], status=None) | |||
|
36 | repo = ctx.repo() | |||
|
37 | # To allow matching file names in the fileset in hgweb directory mode. | |||
|
38 | # See issue4568. | |||
|
39 | object.__setattr__(repo, 'getcwd', lambda: repo.root) | |||
|
40 | return fctx.path() in fileset.getset(mctx, tree) | |||
|
41 | ||||
33 | def filerevision_highlight(orig, web, req, tmpl, fctx): |
|
42 | def filerevision_highlight(orig, web, req, tmpl, fctx): | |
34 | mt = ''.join(tmpl('mimetype', encoding=encoding.encoding)) |
|
43 | mt = ''.join(tmpl('mimetype', encoding=encoding.encoding)) | |
35 | # only pygmentize for mimetype containing 'html' so we both match |
|
44 | # only pygmentize for mimetype containing 'html' so we both match | |
@@ -41,6 +50,8 b' def filerevision_highlight(orig, web, re' | |||||
41 | # pygmentize a html file |
|
50 | # pygmentize a html file | |
42 | if 'html' in mt: |
|
51 | if 'html' in mt: | |
43 | style = web.config('web', 'pygments_style', 'colorful') |
|
52 | style = web.config('web', 'pygments_style', 'colorful') | |
|
53 | expr = web.config('web', 'highlightfiles', "size('<5M')") | |||
|
54 | if checkfctx(fctx, expr): | |||
44 | highlight.pygmentize('fileline', fctx, style, tmpl) |
|
55 | highlight.pygmentize('fileline', fctx, style, tmpl) | |
45 | return orig(web, req, tmpl, fctx) |
|
56 | return orig(web, req, tmpl, fctx) | |
46 |
|
57 | |||
@@ -49,6 +60,8 b' def annotate_highlight(orig, web, req, t' | |||||
49 | if 'html' in mt: |
|
60 | if 'html' in mt: | |
50 | fctx = webutil.filectx(web.repo, req) |
|
61 | fctx = webutil.filectx(web.repo, req) | |
51 | style = web.config('web', 'pygments_style', 'colorful') |
|
62 | style = web.config('web', 'pygments_style', 'colorful') | |
|
63 | expr = web.config('web', 'highlightfiles', "size('<5M')") | |||
|
64 | if checkfctx(fctx, expr): | |||
52 | highlight.pygmentize('annotateline', fctx, style, tmpl) |
|
65 | highlight.pygmentize('annotateline', fctx, style, tmpl) | |
53 | return orig(web, req, tmpl) |
|
66 | return orig(web, req, tmpl) | |
54 |
|
67 |
@@ -5,6 +5,7 b'' | |||||
5 | > highlight = |
|
5 | > highlight = | |
6 | > [web] |
|
6 | > [web] | |
7 | > pygments_style = friendly |
|
7 | > pygments_style = friendly | |
|
8 | > highlightfiles = **.py and size('<100KB') | |||
8 | > EOF |
|
9 | > EOF | |
9 |
$ |
|
10 | $ hg init test | |
10 | $ cd test |
|
11 | $ cd test | |
@@ -590,6 +591,28 b' hgweb highlightcss fruity' | |||||
590 | errors encountered |
|
591 | errors encountered | |
591 |
|
592 | |||
592 | $ cat errors.log |
|
593 | $ cat errors.log | |
|
594 | $ killdaemons.py | |||
|
595 | ||||
|
596 | only highlight C source files | |||
|
597 | ||||
|
598 | $ cat > .hg/hgrc <<EOF | |||
|
599 | > [web] | |||
|
600 | > highlightfiles = **.c | |||
|
601 | > EOF | |||
|
602 | ||||
|
603 | hg serve again | |||
|
604 | ||||
|
605 | $ hg serve -p $HGPORT -d -n test --pid-file=hg.pid -A access.log -E errors.log | |||
|
606 | $ cat hg.pid >> $DAEMON_PIDS | |||
|
607 | ||||
|
608 | test that fileset in highlightfiles works and primes.py is not highlighted | |||
|
609 | ||||
|
610 | $ get-with-headers.py localhost:$HGPORT 'file/tip/primes.py' | grep 'id="l11"' | |||
|
611 | <span id="l11">def primes():</span><a href="#l11"></a> | |||
|
612 | ||||
|
613 | errors encountered | |||
|
614 | ||||
|
615 | $ cat errors.log | |||
593 | $ cd .. |
|
616 | $ cd .. | |
594 | $ hg init eucjp |
|
617 | $ hg init eucjp | |
595 | $ cd eucjp |
|
618 | $ cd eucjp |
General Comments 0
You need to be logged in to leave comments.
Login now