diff options
author | Georg Brandl <georg@python.org> | 2014-10-08 01:18:39 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-10-08 01:18:39 +0200 |
commit | c0ffb8a5babc8e6d1c58b92810f1cc11ae96ff85 (patch) | |
tree | 5a749b88bdba5d7c361c655febcdfc7f90cd9cf4 | |
parent | 2dd7a2b6b1aa538dc9fea6ca581a4657ccd7baf7 (diff) | |
download | pygments-c0ffb8a5babc8e6d1c58b92810f1cc11ae96ff85.tar.gz |
Closes #800: Add "inencoding" option to override "encoding".
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | pygments/formatter.py | 6 | ||||
-rw-r--r-- | pygments/formatters/svg.py | 1 | ||||
-rw-r--r-- | pygments/lexer.py | 4 |
4 files changed, 9 insertions, 5 deletions
@@ -78,6 +78,9 @@ Version 2.0 - The command-line "pygmentize" tool now tries a little harder to find the correct encoding for files and the terminal (#979). +- Added "inencoding" option for lexers to override "encoding" analogous + to "outencoding" (#800). + - Updated the Makefile lexer to yield a little more useful highlighting. - Lexer aliases passed to ``get_lexer_by_name()`` are now case-insensitive. diff --git a/pygments/formatter.py b/pygments/formatter.py index b16ffee8..86821383 100644 --- a/pygments/formatter.py +++ b/pygments/formatter.py @@ -68,10 +68,10 @@ class Formatter(object): self.full = get_bool_opt(options, 'full', False) self.title = options.get('title', '') self.encoding = options.get('encoding', None) or None - if self.encoding == 'guess': - # can happen for pygmentize -O encoding=guess + if self.encoding in ('guess', 'chardet'): + # can happen for e.g. pygmentize -O encoding=guess self.encoding = 'utf-8' - self.encoding = options.get('outencoding', None) or self.encoding + self.encoding = options.get('outencoding') or self.encoding self.options = options def get_style_defs(self, arg=''): diff --git a/pygments/formatters/svg.py b/pygments/formatters/svg.py index 07636943..4e534fa2 100644 --- a/pygments/formatters/svg.py +++ b/pygments/formatters/svg.py @@ -78,7 +78,6 @@ class SvgFormatter(Formatter): filenames = ['*.svg'] def __init__(self, **options): - # XXX outencoding Formatter.__init__(self, **options) self.nowrap = get_bool_opt(options, 'nowrap', False) self.fontfamily = options.get('fontfamily', 'monospace') diff --git a/pygments/lexer.py b/pygments/lexer.py index 8d781e85..d93cb284 100644 --- a/pygments/lexer.py +++ b/pygments/lexer.py @@ -75,6 +75,8 @@ class Lexer(object): Can also be ``'guess'`` to use a simple UTF-8 / Locale / Latin1 detection, or ``'chardet'`` to use the chardet library, if it is installed. + ``inencoding`` + Overrides the ``encoding`` if given. """ #: Name of the lexer @@ -102,7 +104,7 @@ class Lexer(object): self.ensurenl = get_bool_opt(options, 'ensurenl', True) self.tabsize = get_int_opt(options, 'tabsize', 0) self.encoding = options.get('encoding', 'latin1') - # self.encoding = options.get('inencoding', None) or self.encoding + self.encoding = options.get('inencoding') or self.encoding self.filters = [] for filter_ in get_list_opt(options, 'filters', ()): self.add_filter(filter_) |