summaryrefslogtreecommitdiff
path: root/pygments/formatters
diff options
context:
space:
mode:
Diffstat (limited to 'pygments/formatters')
-rw-r--r--pygments/formatters/bbcode.py1
-rw-r--r--pygments/formatters/html.py8
-rw-r--r--pygments/formatters/latex.py8
-rw-r--r--pygments/formatters/other.py5
-rw-r--r--pygments/formatters/terminal.py1
5 files changed, 15 insertions, 8 deletions
diff --git a/pygments/formatters/bbcode.py b/pygments/formatters/bbcode.py
index 228c0a4d..a8663ea9 100644
--- a/pygments/formatters/bbcode.py
+++ b/pygments/formatters/bbcode.py
@@ -76,6 +76,7 @@ class BBCodeFormatter(Formatter):
lasttype = None
for ttype, value in tokensource:
+ value = value.encode(self.encoding)
while ttype not in self.styles:
ttype = ttype.parent
if ttype == lasttype:
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')
diff --git a/pygments/formatters/latex.py b/pygments/formatters/latex.py
index 3cc9d219..27b0c5fe 100644
--- a/pygments/formatters/latex.py
+++ b/pygments/formatters/latex.py
@@ -8,7 +8,7 @@
:copyright: 2006 by Georg Brandl.
:license: GNU LGPL, see LICENSE for more details.
"""
-import StringIO
+import cStringIO
from pygments.formatter import Formatter
from pygments.token import Token
@@ -31,6 +31,7 @@ DOC_TEMPLATE = r'''
\documentclass{%(docclass)s}
\usepackage{fancyvrb}
\usepackage{color}
+\usepackage[%(encoding)s]{inputenc}
%(preamble)s
%(styledefs)s
@@ -151,7 +152,7 @@ class LatexFormatter(Formatter):
if self.full:
realoutfile = outfile
- outfile = StringIO.StringIO()
+ outfile = cStringIO.StringIO()
outfile.write(r'\begin{Verbatim}[commandchars=@\[\]')
if self.linenos:
@@ -164,7 +165,7 @@ class LatexFormatter(Formatter):
outfile.write(']\n')
for ttype, value in tokensource:
- value = escape_tex(value)
+ value = escape_tex(value.encode(self.encoding))
cmd = self.ttype2cmd.get(ttype)
while cmd is None:
ttype = ttype.parent
@@ -187,5 +188,6 @@ class LatexFormatter(Formatter):
dict(docclass = self.docclass,
preamble = self.preamble,
title = self.title,
+ encoding = self.encoding,
styledefs = self.get_style_defs(),
code = outfile.getvalue()))
diff --git a/pygments/formatters/other.py b/pygments/formatters/other.py
index a3657bbb..affbbfc2 100644
--- a/pygments/formatters/other.py
+++ b/pygments/formatters/other.py
@@ -21,7 +21,7 @@ class NullFormatter(Formatter):
"""
def format(self, tokensource, outfile):
for ttype, value in tokensource:
- outfile.write(value)
+ outfile.write(value.encode(self.encoding))
class RawTokenFormatter(Formatter):
@@ -60,8 +60,9 @@ class RawTokenFormatter(Formatter):
flush = outfile.flush
lasttype = None
- lastval = ''
+ lastval = u''
for ttype, value in tokensource:
+ value = value.encode(self.encoding)
if ttype is lasttype:
lastval += value
else:
diff --git a/pygments/formatters/terminal.py b/pygments/formatters/terminal.py
index b1756c54..11f0b26a 100644
--- a/pygments/formatters/terminal.py
+++ b/pygments/formatters/terminal.py
@@ -79,6 +79,7 @@ class TerminalFormatter(Formatter):
def format(self, tokensource, outfile):
dbg = self.debug
for ttype, value in tokensource:
+ value = value.encode(self.encoding)
color = self.colorscheme.get(ttype)
while color is None:
ttype = ttype[:-1]