summaryrefslogtreecommitdiff
path: root/pygments/formatters/html.py
diff options
context:
space:
mode:
authorgbrandl <devnull@localhost>2006-10-31 23:46:24 +0100
committergbrandl <devnull@localhost>2006-10-31 23:46:24 +0100
commit729df9d55ee975be89f18fa90964f19bead60feb (patch)
tree641a0511cbcfa260d1d4e2287f0ede38e50504d8 /pygments/formatters/html.py
parent026d59d92a7b574323484fae8a21c9bcc2401517 (diff)
downloadpygments-729df9d55ee975be89f18fa90964f19bead60feb.tar.gz
[svn] Add encoding support. All processing is now done with unicode strings.
Diffstat (limited to 'pygments/formatters/html.py')
-rw-r--r--pygments/formatters/html.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py
index 00723ede..33aada8d 100644
--- a/pygments/formatters/html.py
+++ b/pygments/formatters/html.py
@@ -8,7 +8,7 @@
:copyright: 2006 by Georg Brandl, Armin Ronacher.
:license: GNU LGPL, see LICENSE for more details.
"""
-import StringIO
+import cStringIO
from pygments.formatter import Formatter
from pygments.token import Token, Text, STANDARD_TYPES
@@ -57,6 +57,7 @@ DOC_TEMPLATE = '''\
<html>
<head>
<title>%(title)s</title>
+ <meta http-equiv="content-type" content="text/html; charset=%(encoding)s">
<style type="text/css">
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
%(styledefs)s
@@ -191,7 +192,7 @@ class HtmlFormatter(Formatter):
write = outfile.write
lspan = ''
for ttype, value in tokensource:
- htmlvalue = escape_html(value)
+ htmlvalue = escape_html(value.encode(self.encoding))
if lnos:
lncount += value.count("\n")
@@ -235,7 +236,7 @@ class HtmlFormatter(Formatter):
div = ('<div' + (self.cssclass and ' class="%s" ' % self.cssclass)
+ (self.cssstyles and ' style="%s"' % self.cssstyles) + '>')
if full or lnos:
- outfile = StringIO.StringIO()
+ outfile = cStringIO.StringIO()
else:
outfile.write(div)
@@ -271,6 +272,7 @@ class HtmlFormatter(Formatter):
realoutfile.write(DOC_TEMPLATE %
dict(title = self.title,
styledefs = self.get_style_defs('body'),
+ encoding = self.encoding,
code = ret))
elif lnos:
realoutfile.write(ret + '</div>\n')