`` tags within a ```` tag, wrapped in a ```` tag. The ``
``'s CSS class can be set by the `cssclass` option."),
44 | #ImageFormatter: ('img', ('img', 'IMG', 'png'), ('*.png',), 'Create a PNG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
45 | #JpgImageFormatter: ('img_jpg', ('jpg', 'jpeg'), ('*.jpg',), 'Create a JPEG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
46 | LatexFormatter: ('LaTeX', ('latex', 'tex'), ('*.tex',), 'Format tokens as LaTeX code. This needs the `fancyvrb` and `color` standard packages.'),
47 | NullFormatter: ('Text only', ('text', 'null'), ('*.txt',), 'Output the text unchanged without any formatting.'),
48 | RawTokenFormatter: ('Raw tokens', ('raw', 'tokens'), ('*.raw',), 'Format tokens as a raw representation for storing token streams.'),
49 | RtfFormatter: ('RTF', ('rtf',), ('*.rtf',), '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\xc2\xae Word\xc2\xae documents.'),
50 | SvgFormatter: ('SVG', ('svg',), ('*.svg',), 'Format tokens as an SVG graphics file. This formatter is still experimental. Each line of code is a ``
`` element with explicit ``x`` and ``y`` coordinates containing ```` elements with the individual token styles.'),
51 | Terminal256Formatter: ('Terminal256', ('terminal256', 'console256', '256'), (), 'Format tokens with ANSI color sequences, for output in a 256-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'),
52 | TerminalFormatter: ('Terminal', ('terminal', 'console'), (), 'Format tokens with ANSI color sequences, for output in a text console. Color sequences are terminated at newlines, so that paging the output works correctly.')
53 | }
54 |
55 | if __name__ == '__main__':
56 | import sys
57 | import os
58 |
59 | # lookup formatters
60 | found_formatters = []
61 | imports = []
62 | sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
63 | for filename in os.listdir('.'):
64 | if filename.endswith('.py') and not filename.startswith('_'):
65 | module_name = 'pygments.formatters.%s' % filename[:-3]
66 | print module_name
67 | module = __import__(module_name, None, None, [''])
68 | for formatter_name in module.__all__:
69 | imports.append((module_name, formatter_name))
70 | formatter = getattr(module, formatter_name)
71 | found_formatters.append(
72 | '%s: %r' % (formatter_name,
73 | (formatter.name,
74 | tuple(formatter.aliases),
75 | tuple(formatter.filenames),
76 | docstring_headline(formatter))))
77 | # sort them, that should make the diff files for svn smaller
78 | found_formatters.sort()
79 | imports.sort()
80 |
81 | # extract useful sourcecode from this file
82 | f = open(__file__)
83 | try:
84 | content = f.read()
85 | finally:
86 | f.close()
87 | header = content[:content.find('# start')]
88 | footer = content[content.find("if __name__ == '__main__':"):]
89 |
90 | # write new file
91 | f = open(__file__, 'w')
92 | f.write(header)
93 | f.write('# start\n')
94 | f.write('\n'.join(['from %s import %s' % imp for imp in imports]))
95 | f.write('\n\n')
96 | f.write('FORMATTERS = {\n %s\n}\n\n' % ',\n '.join(found_formatters))
97 | f.write(footer)
98 | f.close()
99 |
--------------------------------------------------------------------------------
/code_highlight_addon/pygments/formatters/bbcode.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | pygments.formatters.bbcode
4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 |
6 | BBcode formatter.
7 |
8 | :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9 | :license: BSD, see LICENSE for details.
10 | """
11 |
12 |
13 | from pygments.formatter import Formatter
14 | from pygments.util import get_bool_opt
15 |
16 | __all__ = ['BBCodeFormatter']
17 |
18 |
19 | class BBCodeFormatter(Formatter):
20 | """
21 | Format tokens with BBcodes. These formatting codes are used by many
22 | bulletin boards, so you can highlight your sourcecode with pygments before
23 | posting it there.
24 |
25 | This formatter has no support for background colors and borders, as there
26 | are no common BBcode tags for that.
27 |
28 | Some board systems (e.g. phpBB) don't support colors in their [code] tag,
29 | so you can't use the highlighting together with that tag.
30 | Text in a [code] tag usually is shown with a monospace font (which this
31 | formatter can do with the ``monofont`` option) and no spaces (which you
32 | need for indentation) are removed.
33 |
34 | Additional options accepted:
35 |
36 | `style`
37 | The style to use, can be a string or a Style subclass (default:
38 | ``'default'``).
39 |
40 | `codetag`
41 | If set to true, put the output into ``[code]`` tags (default:
42 | ``false``)
43 |
44 | `monofont`
45 | If set to true, add a tag to show the code with a monospace font
46 | (default: ``false``).
47 | """
48 | name = 'BBCode'
49 | aliases = ['bbcode', 'bb']
50 | filenames = []
51 |
52 | def __init__(self, **options):
53 | Formatter.__init__(self, **options)
54 | self._code = get_bool_opt(options, 'codetag', False)
55 | self._mono = get_bool_opt(options, 'monofont', False)
56 |
57 | self.styles = {}
58 | self._make_styles()
59 |
60 | def _make_styles(self):
61 | for ttype, ndef in self.style:
62 | start = end = ''
63 | if ndef['color']:
64 | start += '[color=#%s]' % ndef['color']
65 | end = '[/color]' + end
66 | if ndef['bold']:
67 | start += '[b]'
68 | end = '[/b]' + end
69 | if ndef['italic']:
70 | start += '[i]'
71 | end = '[/i]' + end
72 | if ndef['underline']:
73 | start += '[u]'
74 | end = '[/u]' + end
75 | # there are no common BBcodes for background-color and border
76 |
77 | self.styles[ttype] = start, end
78 |
79 | def format_unencoded(self, tokensource, outfile):
80 | if self._code:
81 | outfile.write('[code]')
82 | if self._mono:
83 | outfile.write('[font=monospace]')
84 |
85 | lastval = ''
86 | lasttype = None
87 |
88 | for ttype, value in tokensource:
89 | while ttype not in self.styles:
90 | ttype = ttype.parent
91 | if ttype == lasttype:
92 | lastval += value
93 | else:
94 | if lastval:
95 | start, end = self.styles[lasttype]
96 | outfile.write(''.join((start, lastval, end)))
97 | lastval = value
98 | lasttype = ttype
99 |
100 | if lastval:
101 | start, end = self.styles[lasttype]
102 | outfile.write(''.join((start, lastval, end)))
103 |
104 | if self._mono:
105 | outfile.write('[/font]')
106 | if self._code:
107 | outfile.write('[/code]')
108 | if self._code or self._mono:
109 | outfile.write('\n')
110 |
--------------------------------------------------------------------------------
/code_highlight_addon/pygments/formatters/img.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | pygments.formatters.img
4 | ~~~~~~~~~~~~~~~~~~~~~~~
5 |
6 | Formatter for Pixmap output.
7 |
8 | :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9 | :license: BSD, see LICENSE for details.
10 | """
11 |
--------------------------------------------------------------------------------
/code_highlight_addon/pygments/formatters/other.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | pygments.formatters.other
4 | ~~~~~~~~~~~~~~~~~~~~~~~~~
5 |
6 | Other formatters: NullFormatter, RawTokenFormatter.
7 |
8 | :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9 | :license: BSD, see LICENSE for details.
10 | """
11 |
12 | from pygments.formatter import Formatter
13 | from pygments.util import OptionError, get_choice_opt, b
14 | from pygments.token import Token
15 | from pygments.console import colorize
16 |
17 | __all__ = ['NullFormatter', 'RawTokenFormatter']
18 |
19 |
20 | class NullFormatter(Formatter):
21 | """
22 | Output the text unchanged without any formatting.
23 | """
24 | name = 'Text only'
25 | aliases = ['text', 'null']
26 | filenames = ['*.txt']
27 |
28 | def format(self, tokensource, outfile):
29 | enc = self.encoding
30 | for ttype, value in tokensource:
31 | if enc:
32 | outfile.write(value.encode(enc))
33 | else:
34 | outfile.write(value)
35 |
36 |
37 | class RawTokenFormatter(Formatter):
38 | r"""
39 | Format tokens as a raw representation for storing token streams.
40 |
41 | The format is ``tokentyperepr(tokenstring)\n``. The output can later
42 | be converted to a token stream with the `RawTokenLexer`, described in the
43 | `lexer list `_.
44 |
45 | Only two options are accepted:
46 |
47 | `compress`
48 | If set to ``'gz'`` or ``'bz2'``, compress the output with the given
49 | compression algorithm after encoding (default: ``''``).
50 | `error_color`
51 | If set to a color name, highlight error tokens using that color. If
52 | set but with no value, defaults to ``'red'``.
53 | *New in Pygments 0.11.*
54 |
55 | """
56 | name = 'Raw tokens'
57 | aliases = ['raw', 'tokens']
58 | filenames = ['*.raw']
59 |
60 | unicodeoutput = False
61 |
62 | def __init__(self, **options):
63 | Formatter.__init__(self, **options)
64 | if self.encoding:
65 | raise OptionError('the raw formatter does not support the '
66 | 'encoding option')
67 | self.encoding = 'ascii' # let pygments.format() do the right thing
68 | self.compress = get_choice_opt(options, 'compress',
69 | ['', 'none', 'gz', 'bz2'], '')
70 | self.error_color = options.get('error_color', None)
71 | if self.error_color is True:
72 | self.error_color = 'red'
73 | if self.error_color is not None:
74 | try:
75 | colorize(self.error_color, '')
76 | except KeyError:
77 | raise ValueError("Invalid color %r specified" %
78 | self.error_color)
79 |
80 | def format(self, tokensource, outfile):
81 | try:
82 | outfile.write(b(''))
83 | except TypeError:
84 | raise TypeError('The raw tokens formatter needs a binary '
85 | 'output file')
86 | if self.compress == 'gz':
87 | import gzip
88 | outfile = gzip.GzipFile('', 'wb', 9, outfile)
89 | def write(text):
90 | outfile.write(text.encode())
91 | flush = outfile.flush
92 | elif self.compress == 'bz2':
93 | import bz2
94 | compressor = bz2.BZ2Compressor(9)
95 | def write(text):
96 | outfile.write(compressor.compress(text.encode()))
97 | def flush():
98 | outfile.write(compressor.flush())
99 | outfile.flush()
100 | else:
101 | def write(text):
102 | outfile.write(text.encode())
103 | flush = outfile.flush
104 |
105 | lasttype = None
106 | lastval = u''
107 | if self.error_color:
108 | for ttype, value in tokensource:
109 | line = "%s\t%r\n" % (ttype, value)
110 | if ttype is Token.Error:
111 | write(colorize(self.error_color, line))
112 | else:
113 | write(line)
114 | else:
115 | for ttype, value in tokensource:
116 | write("%s\t%r\n" % (ttype, value))
117 | flush()
118 |
--------------------------------------------------------------------------------
/code_highlight_addon/pygments/formatters/rtf.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | pygments.formatters.rtf
4 | ~~~~~~~~~~~~~~~~~~~~~~~
5 |
6 | A formatter that generates RTF files.
7 |
8 | :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9 | :license: BSD, see LICENSE for details.
10 | """
11 |
12 | from pygments.formatter import Formatter
13 |
14 |
15 | __all__ = ['RtfFormatter']
16 |
17 |
18 | class RtfFormatter(Formatter):
19 | """
20 | Format tokens as RTF markup. This formatter automatically outputs full RTF
21 | documents with color information and other useful stuff. Perfect for Copy and
22 | Paste into Microsoft® Word® documents.
23 |
24 | *New in Pygments 0.6.*
25 |
26 | Additional options accepted:
27 |
28 | `style`
29 | The style to use, can be a string or a Style subclass (default:
30 | ``'default'``).
31 |
32 | `fontface`
33 | The used font famliy, for example ``Bitstream Vera Sans``. Defaults to
34 | some generic font which is supposed to have fixed width.
35 | """
36 | name = 'RTF'
37 | aliases = ['rtf']
38 | filenames = ['*.rtf']
39 |
40 | unicodeoutput = False
41 |
42 | def __init__(self, **options):
43 | """
44 | Additional options accepted:
45 |
46 | ``fontface``
47 | Name of the font used. Could for example be ``'Courier New'``
48 | to further specify the default which is ``'\fmodern'``. The RTF
49 | specification claims that ``\fmodern`` are "Fixed-pitch serif
50 | and sans serif fonts". Hope every RTF implementation thinks
51 | the same about modern...
52 | """
53 | Formatter.__init__(self, **options)
54 | self.fontface = options.get('fontface') or ''
55 |
56 | def _escape(self, text):
57 | return text.replace('\\', '\\\\') \
58 | .replace('{', '\\{') \
59 | .replace('}', '\\}')
60 |
61 | def _escape_text(self, text):
62 | # empty strings, should give a small performance improvment
63 | if not text:
64 | return ''
65 |
66 | # escape text
67 | text = self._escape(text)
68 | if self.encoding in ('utf-8', 'utf-16', 'utf-32'):
69 | encoding = 'iso-8859-15'
70 | else:
71 | encoding = self.encoding or 'iso-8859-15'
72 |
73 | buf = []
74 | for c in text:
75 | if ord(c) > 128:
76 | ansic = c.encode(encoding, 'ignore') or '?'
77 | if ord(ansic) > 128:
78 | ansic = '\\\'%x' % ord(ansic)
79 | else:
80 | ansic = c
81 | buf.append(r'\ud{\u%d%s}' % (ord(c), ansic))
82 | else:
83 | buf.append(str(c))
84 |
85 | return ''.join(buf).replace('\n', '\\par\n')
86 |
87 | def format_unencoded(self, tokensource, outfile):
88 | # rtf 1.8 header
89 | outfile.write(r'{\rtf1\ansi\deff0'
90 | r'{\fonttbl{\f0\fmodern\fprq1\fcharset0%s;}}'
91 | r'{\colortbl;' % (self.fontface and
92 | ' ' + self._escape(self.fontface) or
93 | ''))
94 |
95 | # convert colors and save them in a mapping to access them later.
96 | color_mapping = {}
97 | offset = 1
98 | for _, style in self.style:
99 | for color in style['color'], style['bgcolor'], style['border']:
100 | if color and color not in color_mapping:
101 | color_mapping[color] = offset
102 | outfile.write(r'\red%d\green%d\blue%d;' % (
103 | int(color[0:2], 16),
104 | int(color[2:4], 16),
105 | int(color[4:6], 16)
106 | ))
107 | offset += 1
108 | outfile.write(r'}\f0')
109 |
110 | # highlight stream
111 | for ttype, value in tokensource:
112 | while not self.style.styles_token(ttype) and ttype.parent:
113 | ttype = ttype.parent
114 | style = self.style.style_for_token(ttype)
115 | buf = []
116 | if style['bgcolor']:
117 | buf.append(r'\cb%d' % color_mapping[style['bgcolor']])
118 | if style['color']:
119 | buf.append(r'\cf%d' % color_mapping[style['color']])
120 | if style['bold']:
121 | buf.append(r'\b')
122 | if style['italic']:
123 | buf.append(r'\i')
124 | if style['underline']:
125 | buf.append(r'\ul')
126 | if style['border']:
127 | buf.append(r'\chbrdr\chcfpat%d' %
128 | color_mapping[style['border']])
129 | start = ''.join(buf)
130 | if start:
131 | outfile.write('{%s ' % start)
132 | outfile.write(self._escape_text(value))
133 | if start:
134 | outfile.write('}')
135 |
136 | outfile.write('}')
137 |
--------------------------------------------------------------------------------
/code_highlight_addon/pygments/formatters/svg.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | pygments.formatters.svg
4 | ~~~~~~~~~~~~~~~~~~~~~~~
5 |
6 | Formatter for SVG output.
7 |
8 | :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9 | :license: BSD, see LICENSE for details.
10 | """
11 |
12 | from pygments.formatter import Formatter
13 | from pygments.util import get_bool_opt, get_int_opt
14 |
15 | __all__ = ['SvgFormatter']
16 |
17 |
18 | def escape_html(text):
19 | """Escape &, <, > as well as single and double quotes for HTML."""
20 | return text.replace('&', '&'). \
21 | replace('<', '<'). \
22 | replace('>', '>'). \
23 | replace('"', '"'). \
24 | replace("'", ''')
25 |
26 |
27 | class2style = {}
28 |
29 | class SvgFormatter(Formatter):
30 | """
31 | Format tokens as an SVG graphics file. This formatter is still experimental.
32 | Each line of code is a ```` element with explicit ``x`` and ``y``
33 | coordinates containing ```` elements with the individual token styles.
34 |
35 | By default, this formatter outputs a full SVG document including doctype
36 | declaration and the ``