Show More
@@ -32,26 +32,27 b' def pygmentize(field, fctx, style, tmpl)' | |||||
32 | if util.binary(text): |
|
32 | if util.binary(text): | |
33 | return |
|
33 | return | |
34 |
|
34 | |||
35 | # avoid UnicodeDecodeError in pygments |
|
35 | # Pygments is best used with Unicode strings: | |
36 | text = encoding.tolocal(text) |
|
36 | # <http://pygments.org/docs/unicode/> | |
|
37 | text = text.decode(encoding.encoding, 'replace') | |||
37 |
|
38 | |||
38 | # To get multi-line strings right, we can't format line-by-line |
|
39 | # To get multi-line strings right, we can't format line-by-line | |
39 | try: |
|
40 | try: | |
40 |
lexer = guess_lexer_for_filename(fctx.path(), text[:1024] |
|
41 | lexer = guess_lexer_for_filename(fctx.path(), text[:1024]) | |
41 | encoding=encoding.encoding) |
|
|||
42 | except (ClassNotFound, ValueError): |
|
42 | except (ClassNotFound, ValueError): | |
43 | try: |
|
43 | try: | |
44 |
lexer = guess_lexer(text[:1024] |
|
44 | lexer = guess_lexer(text[:1024]) | |
45 | except (ClassNotFound, ValueError): |
|
45 | except (ClassNotFound, ValueError): | |
46 |
lexer = TextLexer( |
|
46 | lexer = TextLexer() | |
47 |
|
47 | |||
48 |
formatter = HtmlFormatter(style=style |
|
48 | formatter = HtmlFormatter(style=style) | |
49 |
|
49 | |||
50 | colorized = highlight(text, lexer, formatter) |
|
50 | colorized = highlight(text, lexer, formatter) | |
51 | # strip wrapping div |
|
51 | # strip wrapping div | |
52 | colorized = colorized[:colorized.find('\n</pre>')] |
|
52 | colorized = colorized[:colorized.find('\n</pre>')] | |
53 | colorized = colorized[colorized.find('<pre>')+5:] |
|
53 | colorized = colorized[colorized.find('<pre>')+5:] | |
54 | coloriter = iter(colorized.splitlines()) |
|
54 | coloriter = (s.encode(encoding.encoding, 'replace') | |
|
55 | for s in colorized.splitlines()) | |||
55 |
|
56 | |||
56 | tmpl.filters['colorize'] = lambda x: coloriter.next() |
|
57 | tmpl.filters['colorize'] = lambda x: coloriter.next() | |
57 |
|
58 |
@@ -121,3 +121,28 b' rm out' | |||||
121 |
|
121 | |||
122 | echo % errors encountered |
|
122 | echo % errors encountered | |
123 | cat errors.log |
|
123 | cat errors.log | |
|
124 | ||||
|
125 | cd .. | |||
|
126 | hg init eucjp | |||
|
127 | cd eucjp | |||
|
128 | ||||
|
129 | printf '\265\376\n' >> eucjp.txt # Japanese kanji "Kyo" | |||
|
130 | ||||
|
131 | hg ci -Ama | |||
|
132 | ||||
|
133 | hgserveget () { | |||
|
134 | "$TESTDIR/killdaemons.py" | |||
|
135 | echo % HGENCODING="$1" hg serve | |||
|
136 | HGENCODING="$1" hg serve -p $HGPORT -d -n test --pid-file=hg.pid -E errors.log | |||
|
137 | cat hg.pid >> $DAEMON_PIDS | |||
|
138 | ||||
|
139 | echo % hgweb filerevision, html | |||
|
140 | "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/file/tip/$2" \ | |||
|
141 | | grep '<div class="parity0 source">' | $TESTDIR/printrepr.py | |||
|
142 | echo % errors encountered | |||
|
143 | cat errors.log | |||
|
144 | } | |||
|
145 | ||||
|
146 | hgserveget euc-jp eucjp.txt | |||
|
147 | hgserveget utf-8 eucjp.txt | |||
|
148 | hgserveget us-ascii eucjp.txt |
@@ -538,3 +538,16 b' 200 Script output follows' | |||||
538 | /* pygments_style = fruity */ |
|
538 | /* pygments_style = fruity */ | |
539 |
|
539 | |||
540 | % errors encountered |
|
540 | % errors encountered | |
|
541 | adding eucjp.txt | |||
|
542 | % HGENCODING=euc-jp hg serve | |||
|
543 | % hgweb filerevision, html | |||
|
544 | <div class="parity0 source"><a href="#l1" id="l1"> 1</a> \xb5\xfe</div> | |||
|
545 | % errors encountered | |||
|
546 | % HGENCODING=utf-8 hg serve | |||
|
547 | % hgweb filerevision, html | |||
|
548 | <div class="parity0 source"><a href="#l1" id="l1"> 1</a> \xef\xbf\xbd\xef\xbf\xbd</div> | |||
|
549 | % errors encountered | |||
|
550 | % HGENCODING=us-ascii hg serve | |||
|
551 | % hgweb filerevision, html | |||
|
552 | <div class="parity0 source"><a href="#l1" id="l1"> 1</a> ??</div> | |||
|
553 | % errors encountered |
General Comments 0
You need to be logged in to leave comments.
Login now