Show More
@@ -13,23 +13,32 b'' | |||
|
13 | 13 | It depends on the Pygments syntax highlighting library: |
|
14 | 14 | http://pygments.org/ |
|
15 | 15 | |
|
16 |
There |
|
|
16 | There are two configuration options:: | |
|
17 | 17 | |
|
18 | 18 | [web] |
|
19 | pygments_style = <style> | |
|
20 | ||
|
21 | The default is 'colorful'. | |
|
19 | pygments_style = <style> (default: colorful) | |
|
20 | highlightfiles = <fileset> (default: size('<5M')) | |
|
22 | 21 | """ |
|
23 | 22 | |
|
24 | 23 | import highlight |
|
25 | 24 | from mercurial.hgweb import webcommands, webutil, common |
|
26 | from mercurial import extensions, encoding | |
|
25 | from mercurial import extensions, encoding, fileset | |
|
27 | 26 | # Note for extension authors: ONLY specify testedwith = 'internal' for |
|
28 | 27 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
|
29 | 28 | # be specifying the version(s) of Mercurial they are tested with, or |
|
30 | 29 | # leave the attribute unspecified. |
|
31 | 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 | 42 | def filerevision_highlight(orig, web, req, tmpl, fctx): |
|
34 | 43 | mt = ''.join(tmpl('mimetype', encoding=encoding.encoding)) |
|
35 | 44 | # only pygmentize for mimetype containing 'html' so we both match |
@@ -41,7 +50,9 b' def filerevision_highlight(orig, web, re' | |||
|
41 | 50 | # pygmentize a html file |
|
42 | 51 | if 'html' in mt: |
|
43 | 52 | style = web.config('web', 'pygments_style', 'colorful') |
|
44 | highlight.pygmentize('fileline', fctx, style, tmpl) | |
|
53 | expr = web.config('web', 'highlightfiles', "size('<5M')") | |
|
54 | if checkfctx(fctx, expr): | |
|
55 | highlight.pygmentize('fileline', fctx, style, tmpl) | |
|
45 | 56 | return orig(web, req, tmpl, fctx) |
|
46 | 57 | |
|
47 | 58 | def annotate_highlight(orig, web, req, tmpl): |
@@ -49,7 +60,9 b' def annotate_highlight(orig, web, req, t' | |||
|
49 | 60 | if 'html' in mt: |
|
50 | 61 | fctx = webutil.filectx(web.repo, req) |
|
51 | 62 | style = web.config('web', 'pygments_style', 'colorful') |
|
52 | highlight.pygmentize('annotateline', fctx, style, tmpl) | |
|
63 | expr = web.config('web', 'highlightfiles', "size('<5M')") | |
|
64 | if checkfctx(fctx, expr): | |
|
65 | highlight.pygmentize('annotateline', fctx, style, tmpl) | |
|
53 | 66 | return orig(web, req, tmpl) |
|
54 | 67 | |
|
55 | 68 | def generate_css(web, req, tmpl): |
@@ -5,6 +5,7 b'' | |||
|
5 | 5 | > highlight = |
|
6 | 6 | > [web] |
|
7 | 7 | > pygments_style = friendly |
|
8 | > highlightfiles = **.py and size('<100KB') | |
|
8 | 9 | > EOF |
|
9 | 10 |
$ |
|
10 | 11 | $ cd test |
@@ -590,6 +591,28 b' hgweb highlightcss fruity' | |||
|
590 | 591 | errors encountered |
|
591 | 592 | |
|
592 | 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 | 616 | $ cd .. |
|
594 | 617 | $ hg init eucjp |
|
595 | 618 | $ cd eucjp |
General Comments 0
You need to be logged in to leave comments.
Login now