Mercurial > hg
comparison tests/test-highlight.out @ 9424:799373ff2554
highlight: fixes garbled text in non-UTF-8 environment
This patch treats all files inside repository as encoded by
locale's encoding when pygmentize.
We can assume that most files are written in locale's encoding,
but current implementation treats them as UTF-8.
So there's no way to specify the encoding of files.
Current implementation, db7557359636 (issue1341):
1. Convert original `text`, which is treated as UTF-8, to locale's encoding.
`encoding.tolocal()` is the method to convert from internal UTF-8 to local.
If original `text` is not UTF-8, e.g. Japanese EUC-JP, some characters
become garbled here.
2. pygmentize, with no UnicodeDecodeError.
This patch:
1. Convert original `text`, which is treated as locale's encoding, to unicode.
Pygments prefers unicode object than raw str. [1]_
If original `text` is not encoded by locale's encoding, some characters
become garbled here.
2. pygmentize, also with no UnicodeDecodeError :)
3. Convert unicode back to raw str, which is encoded by locale's.
.. [1] http://pygments.org/docs/unicode/
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 29 Aug 2009 15:24:15 +0900 |
parents | 1de6e7e1bb9f |
children | b42b03308ae9 |
comparison
equal
deleted
inserted
replaced
9423:1444a42f6052 | 9424:799373ff2554 |
---|---|
536 200 Script output follows | 536 200 Script output follows |
537 | 537 |
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 |