Coverage for pygments.formatters.rtf : 89%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*- pygments.formatters.rtf ~~~~~~~~~~~~~~~~~~~~~~~
A formatter that generates RTF files.
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """
""" Format tokens as RTF markup. This formatter automatically outputs full RTF documents with color information and other useful stuff. Perfect for Copy and Paste into Microsoft(R) Word(R) documents.
Please note that ``encoding`` and ``outencoding`` options are ignored. The RTF format is ASCII natively, but handles unicode characters correctly thanks to escape sequences.
.. versionadded:: 0.6
Additional options accepted:
`style` The style to use, can be a string or a Style subclass (default: ``'default'``).
`fontface` The used font famliy, for example ``Bitstream Vera Sans``. Defaults to some generic font which is supposed to have fixed width.
`fontsize` Size of the font used. Size is specified in half points. The default is 24 half-points, giving a size 12 font.
.. versionadded:: 2.0 """
r""" Additional options accepted:
``fontface`` Name of the font used. Could for example be ``'Courier New'`` to further specify the default which is ``'\fmodern'``. The RTF specification claims that ``\fmodern`` are "Fixed-pitch serif and sans serif fonts". Hope every RTF implementation thinks the same about modern...
"""
.replace(u'{', u'\\{') \ .replace(u'}', u'\\}')
# empty strings, should give a small performance improvment return u''
# escape text
# ASCII character # single unicode escape sequence # RTF limits unicode to 16 bits. # Force surrogate pairs
# rtf 1.8 header u'{\\fonttbl{\\f0\\fmodern\\fprq1\\fcharset0%s;}}' u'{\\colortbl;' % (self.fontface and u' ' + self._escape(self.fontface) or u''))
# convert colors and save them in a mapping to access them later. int(color[0:2], 16), int(color[2:4], 16), int(color[4:6], 16) )) outfile.write(u'\\fs%d' % (self.fontsize))
# highlight stream ttype = ttype.parent buf.append(u'\\cb%d' % color_mapping[style['bgcolor']]) buf.append(u'\\i') buf.append(u'\\ul') buf.append(u'\\chbrdr\\chcfpat%d' % color_mapping[style['border']])
|