summaryrefslogtreecommitdiff
path: root/pygments/formatters/html.py
diff options
context:
space:
mode:
authorgbrandl <devnull@localhost>2009-03-31 10:26:55 -0500
committergbrandl <devnull@localhost>2009-03-31 10:26:55 -0500
commit7b95efab48d9ec79e995bf4d6db10fd049e3395a (patch)
tree48fc9b840dab83976a85af85d1c705dbaa051a0b /pygments/formatters/html.py
parentf12c878ed096137c91658a0f62f0070e08c2afea (diff)
downloadpygments-7b95efab48d9ec79e995bf4d6db10fd049e3395a.tar.gz
Port Pygments to Python 3.1.
Diffstat (limited to 'pygments/formatters/html.py')
-rw-r--r--pygments/formatters/html.py28
1 files changed, 13 insertions, 15 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py
index b99fdea2..51e8cda1 100644
--- a/pygments/formatters/html.py
+++ b/pygments/formatters/html.py
@@ -18,7 +18,7 @@ except NameError:
from pygments.formatter import Formatter
from pygments.token import Token, Text, STANDARD_TYPES
-from pygments.util import get_bool_opt, get_int_opt, get_list_opt
+from pygments.util import get_bool_opt, get_int_opt, get_list_opt, bytes
__all__ = ['HtmlFormatter']
@@ -342,14 +342,14 @@ class HtmlFormatter(Formatter):
def __init__(self, **options):
Formatter.__init__(self, **options)
- self.title = self._encodeifneeded(self.title)
+ self.title = self._decodeifneeded(self.title)
self.nowrap = get_bool_opt(options, 'nowrap', False)
self.noclasses = get_bool_opt(options, 'noclasses', False)
self.classprefix = options.get('classprefix', '')
- self.cssclass = self._encodeifneeded(options.get('cssclass', 'highlight'))
- self.cssstyles = self._encodeifneeded(options.get('cssstyles', ''))
- self.prestyles = self._encodeifneeded(options.get('prestyles', ''))
- self.cssfile = self._encodeifneeded(options.get('cssfile', ''))
+ self.cssclass = self._decodeifneeded(options.get('cssclass', 'highlight'))
+ self.cssstyles = self._decodeifneeded(options.get('cssstyles', ''))
+ self.prestyles = self._decodeifneeded(options.get('prestyles', ''))
+ self.cssfile = self._decodeifneeded(options.get('cssfile', ''))
self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile', False)
linenos = options.get('linenos', False)
@@ -448,10 +448,12 @@ class HtmlFormatter(Formatter):
(prefix(''), self.style.highlight_color))
return '\n'.join(lines)
- def _encodeifneeded(self, value):
- if not self.encoding or isinstance(value, str):
- return value
- return value.encode(self.encoding)
+ def _decodeifneeded(self, value):
+ if isinstance(value, bytes):
+ if self.encoding:
+ return value.decode(self.encoding)
+ return value.decode()
+ return value
def _wrap_full(self, inner, outfile):
if self.cssfile:
@@ -599,7 +601,6 @@ class HtmlFormatter(Formatter):
Yield individual lines.
"""
nocls = self.noclasses
- enc = self.encoding
lsep = self.lineseparator
# for <span style=""> lookup only
getcls = self.ttype2class.get
@@ -618,9 +619,6 @@ class HtmlFormatter(Formatter):
cls = self._get_css_class(ttype)
cspan = cls and '<span class="%s">' % cls or ''
- if enc:
- value = value.encode(enc)
-
parts = escape_html(value).split('\n')
# for all but the last line
@@ -675,7 +673,7 @@ class HtmlFormatter(Formatter):
"""
return self._wrap_div(self._wrap_pre(source))
- def format(self, tokensource, outfile):
+ def format_unencoded(self, tokensource, outfile):
"""
The formatting process uses several nested generators; which of
them are used is determined by the user's options.