summaryrefslogtreecommitdiff
path: root/pygments/formatters/rtf.py
diff options
context:
space:
mode:
Diffstat (limited to 'pygments/formatters/rtf.py')
-rw-r--r--pygments/formatters/rtf.py52
1 files changed, 26 insertions, 26 deletions
diff --git a/pygments/formatters/rtf.py b/pygments/formatters/rtf.py
index 7f51bacd..34393d47 100644
--- a/pygments/formatters/rtf.py
+++ b/pygments/formatters/rtf.py
@@ -10,7 +10,7 @@
"""
from pygments.formatter import Formatter
-from pygments.util import get_int_opt, _surrogatepair
+from pygments.util import get_int_opt, surrogatepair
__all__ = ['RtfFormatter']
@@ -65,14 +65,14 @@ class RtfFormatter(Formatter):
self.fontsize = get_int_opt(options, 'fontsize', 0)
def _escape(self, text):
- return text.replace(u'\\', u'\\\\') \
- .replace(u'{', u'\\{') \
- .replace(u'}', u'\\}')
+ return text.replace('\\', '\\\\') \
+ .replace('{', '\\{') \
+ .replace('}', '\\}')
def _escape_text(self, text):
# empty strings, should give a small performance improvement
if not text:
- return u''
+ return ''
# escape text
text = self._escape(text)
@@ -85,21 +85,21 @@ class RtfFormatter(Formatter):
buf.append(str(c))
elif (2**7) <= cn < (2**16):
# single unicode escape sequence
- buf.append(u'{\\u%d}' % cn)
+ buf.append('{\\u%d}' % cn)
elif (2**16) <= cn:
# RTF limits unicode to 16 bits.
# Force surrogate pairs
- buf.append(u'{\\u%d}{\\u%d}' % _surrogatepair(cn))
+ buf.append('{\\u%d}{\\u%d}' % surrogatepair(cn))
- return u''.join(buf).replace(u'\n', u'\\par\n')
+ return ''.join(buf).replace('\n', '\\par\n')
def format_unencoded(self, tokensource, outfile):
# rtf 1.8 header
- outfile.write(u'{\\rtf1\\ansi\\uc0\\deff0'
- u'{\\fonttbl{\\f0\\fmodern\\fprq1\\fcharset0%s;}}'
- u'{\\colortbl;' % (self.fontface and
- u' ' + self._escape(self.fontface) or
- u''))
+ outfile.write('{\\rtf1\\ansi\\uc0\\deff0'
+ '{\\fonttbl{\\f0\\fmodern\\fprq1\\fcharset0%s;}}'
+ '{\\colortbl;' % (self.fontface and
+ ' ' + self._escape(self.fontface) or
+ ''))
# convert colors and save them in a mapping to access them later.
color_mapping = {}
@@ -108,15 +108,15 @@ class RtfFormatter(Formatter):
for color in style['color'], style['bgcolor'], style['border']:
if color and color not in color_mapping:
color_mapping[color] = offset
- outfile.write(u'\\red%d\\green%d\\blue%d;' % (
+ outfile.write('\\red%d\\green%d\\blue%d;' % (
int(color[0:2], 16),
int(color[2:4], 16),
int(color[4:6], 16)
))
offset += 1
- outfile.write(u'}\\f0 ')
+ outfile.write('}\\f0 ')
if self.fontsize:
- outfile.write(u'\\fs%d' % (self.fontsize))
+ outfile.write('\\fs%d' % self.fontsize)
# highlight stream
for ttype, value in tokensource:
@@ -125,23 +125,23 @@ class RtfFormatter(Formatter):
style = self.style.style_for_token(ttype)
buf = []
if style['bgcolor']:
- buf.append(u'\\cb%d' % color_mapping[style['bgcolor']])
+ buf.append('\\cb%d' % color_mapping[style['bgcolor']])
if style['color']:
- buf.append(u'\\cf%d' % color_mapping[style['color']])
+ buf.append('\\cf%d' % color_mapping[style['color']])
if style['bold']:
- buf.append(u'\\b')
+ buf.append('\\b')
if style['italic']:
- buf.append(u'\\i')
+ buf.append('\\i')
if style['underline']:
- buf.append(u'\\ul')
+ buf.append('\\ul')
if style['border']:
- buf.append(u'\\chbrdr\\chcfpat%d' %
+ buf.append('\\chbrdr\\chcfpat%d' %
color_mapping[style['border']])
- start = u''.join(buf)
+ start = ''.join(buf)
if start:
- outfile.write(u'{%s ' % start)
+ outfile.write('{%s ' % start)
outfile.write(self._escape_text(value))
if start:
- outfile.write(u'}')
+ outfile.write('}')
- outfile.write(u'}')
+ outfile.write('}')