`` tag. The ``
``'s CSS class can be set by the `cssclass` option."),
23 | 'ImageFormatter': ('pygments.formatters.img', '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.'),
24 | 'JpgImageFormatter': ('pygments.formatters.img', '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.'),
25 | 'LatexFormatter': ('pygments.formatters.latex', 'LaTeX', ('latex', 'tex'), ('*.tex',), 'Format tokens as LaTeX code. This needs the `fancyvrb` and `color` standard packages.'),
26 | 'NullFormatter': ('pygments.formatters.other', 'Text only', ('text', 'null'), ('*.txt',), 'Output the text unchanged without any formatting.'),
27 | 'RawTokenFormatter': ('pygments.formatters.other', 'Raw tokens', ('raw', 'tokens'), ('*.raw',), 'Format tokens as a raw representation for storing token streams.'),
28 | 'RtfFormatter': ('pygments.formatters.rtf', '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(R) Word(R) documents.'),
29 | 'SvgFormatter': ('pygments.formatters.svg', '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.'),
30 | 'Terminal256Formatter': ('pygments.formatters.terminal256', '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.'),
31 | 'TerminalFormatter': ('pygments.formatters.terminal', '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.'),
32 | 'TestcaseFormatter': ('pygments.formatters.other', 'Testcase', ('testcase',), (), 'Format tokens as appropriate for a new testcase.')
33 | }
34 |
35 |
36 | if __name__ == '__main__': # pragma: no cover
37 | import sys
38 | import os
39 |
40 | # lookup formatters
41 | found_formatters = []
42 | imports = []
43 | sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
44 | from pygments.util import docstring_headline
45 |
46 | for root, dirs, files in os.walk('.'):
47 | for filename in files:
48 | if filename.endswith('.py') and not filename.startswith('_'):
49 | module_name = 'pygments.formatters%s.%s' % (
50 | root[1:].replace('/', '.'), filename[:-3])
51 | print(module_name)
52 | module = __import__(module_name, None, None, [''])
53 | for formatter_name in module.__all__:
54 | formatter = getattr(module, formatter_name)
55 | found_formatters.append(
56 | '%r: %r' % (formatter_name,
57 | (module_name,
58 | formatter.name,
59 | tuple(formatter.aliases),
60 | tuple(formatter.filenames),
61 | docstring_headline(formatter))))
62 | # sort them to make the diff minimal
63 | found_formatters.sort()
64 |
65 | # extract useful sourcecode from this file
66 | with open(__file__) as fp:
67 | content = fp.read()
68 | header = content[:content.find('FORMATTERS = {')]
69 | footer = content[content.find("if __name__ == '__main__':"):]
70 |
71 | # write new file
72 | with open(__file__, 'w') as fp:
73 | fp.write(header)
74 | fp.write('FORMATTERS = {\n %s\n}\n\n' % ',\n '.join(found_formatters))
75 | fp.write(footer)
76 |
77 | print ('=== %d formatters processed.' % len(found_formatters))
78 |
--------------------------------------------------------------------------------
/DrawBot.glyphsPlugin/Contents/Resources/pygments/formatters/bbcode.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | pygments.formatters.bbcode
4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 |
6 | BBcode formatter.
7 |
8 | :copyright: Copyright 2006-2014 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 |
--------------------------------------------------------------------------------
/DrawBot.glyphsPlugin/Contents/Resources/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-2014 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
14 | from pygments.token import Token
15 | from pygments.console import colorize
16 |
17 | __all__ = ['NullFormatter', 'RawTokenFormatter', 'TestcaseFormatter']
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 | :doc:`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 |
54 | .. versionadded:: 0.11
55 |
56 | """
57 | name = 'Raw tokens'
58 | aliases = ['raw', 'tokens']
59 | filenames = ['*.raw']
60 |
61 | unicodeoutput = False
62 |
63 | def __init__(self, **options):
64 | Formatter.__init__(self, **options)
65 | # We ignore self.encoding if it is set, since it gets set for lexer
66 | # and formatter if given with -Oencoding on the command line.
67 | # The RawTokenFormatter outputs only ASCII. Override here.
68 | self.encoding = 'ascii' # let pygments.format() do the right thing
69 | self.compress = get_choice_opt(options, 'compress',
70 | ['', 'none', 'gz', 'bz2'], '')
71 | self.error_color = options.get('error_color', None)
72 | if self.error_color is True:
73 | self.error_color = 'red'
74 | if self.error_color is not None:
75 | try:
76 | colorize(self.error_color, '')
77 | except KeyError:
78 | raise ValueError("Invalid color %r specified" %
79 | self.error_color)
80 |
81 | def format(self, tokensource, outfile):
82 | try:
83 | outfile.write(b'')
84 | except TypeError:
85 | raise TypeError('The raw tokens formatter needs a binary '
86 | 'output file')
87 | if self.compress == 'gz':
88 | import gzip
89 | outfile = gzip.GzipFile('', 'wb', 9, outfile)
90 | def write(text):
91 | outfile.write(text.encode())
92 | flush = outfile.flush
93 | elif self.compress == 'bz2':
94 | import bz2
95 | compressor = bz2.BZ2Compressor(9)
96 | def write(text):
97 | outfile.write(compressor.compress(text.encode()))
98 | def flush():
99 | outfile.write(compressor.flush())
100 | outfile.flush()
101 | else:
102 | def write(text):
103 | outfile.write(text.encode())
104 | flush = outfile.flush
105 |
106 | if self.error_color:
107 | for ttype, value in tokensource:
108 | line = "%s\t%r\n" % (ttype, value)
109 | if ttype is Token.Error:
110 | write(colorize(self.error_color, line))
111 | else:
112 | write(line)
113 | else:
114 | for ttype, value in tokensource:
115 | write("%s\t%r\n" % (ttype, value))
116 | flush()
117 |
118 | TESTCASE_BEFORE = u'''\
119 | def testNeedsName(self):
120 | fragment = %r
121 | tokens = [
122 | '''
123 | TESTCASE_AFTER = u'''\
124 | ]
125 | self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
126 | '''
127 |
128 |
129 | class TestcaseFormatter(Formatter):
130 | """
131 | Format tokens as appropriate for a new testcase.
132 |
133 | .. versionadded:: 2.0
134 | """
135 | name = 'Testcase'
136 | aliases = ['testcase']
137 |
138 | def __init__(self, **options):
139 | Formatter.__init__(self, **options)
140 | if self.encoding is not None and self.encoding != 'utf-8':
141 | raise ValueError("Only None and utf-8 are allowed encodings.")
142 |
143 | def format(self, tokensource, outfile):
144 | indentation = ' ' * 12
145 | rawbuf = []
146 | outbuf = []
147 | for ttype, value in tokensource:
148 | rawbuf.append(value)
149 | outbuf.append('%s(%s, %r),\n' % (indentation, ttype, value))
150 |
151 | before = TESTCASE_BEFORE % (u''.join(rawbuf),)
152 | during = u''.join(outbuf)
153 | after = TESTCASE_AFTER
154 | if self.encoding is None:
155 | outfile.write(before + during + after)
156 | else:
157 | outfile.write(before.encode('utf-8'))
158 | outfile.write(during.encode('utf-8'))
159 | outfile.write(after.encode('utf-8'))
160 | outfile.flush()
161 |
--------------------------------------------------------------------------------
/DrawBot.glyphsPlugin/Contents/Resources/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-2014 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_int_opt, _surrogatepair
14 |
15 |
16 | __all__ = ['RtfFormatter']
17 |
18 |
19 | class RtfFormatter(Formatter):
20 | """
21 | Format tokens as RTF markup. This formatter automatically outputs full RTF
22 | documents with color information and other useful stuff. Perfect for Copy and
23 | Paste into Microsoft(R) Word(R) documents.
24 |
25 | Please note that ``encoding`` and ``outencoding`` options are ignored.
26 | The RTF format is ASCII natively, but handles unicode characters correctly
27 | thanks to escape sequences.
28 |
29 | .. versionadded:: 0.6
30 |
31 | Additional options accepted:
32 |
33 | `style`
34 | The style to use, can be a string or a Style subclass (default:
35 | ``'default'``).
36 |
37 | `fontface`
38 | The used font famliy, for example ``Bitstream Vera Sans``. Defaults to
39 | some generic font which is supposed to have fixed width.
40 |
41 | `fontsize`
42 | Size of the font used. Size is specified in half points. The
43 | default is 24 half-points, giving a size 12 font.
44 |
45 | .. versionadded:: 2.0
46 | """
47 | name = 'RTF'
48 | aliases = ['rtf']
49 | filenames = ['*.rtf']
50 |
51 | def __init__(self, **options):
52 | r"""
53 | Additional options accepted:
54 |
55 | ``fontface``
56 | Name of the font used. Could for example be ``'Courier New'``
57 | to further specify the default which is ``'\fmodern'``. The RTF
58 | specification claims that ``\fmodern`` are "Fixed-pitch serif
59 | and sans serif fonts". Hope every RTF implementation thinks
60 | the same about modern...
61 |
62 | """
63 | Formatter.__init__(self, **options)
64 | self.fontface = options.get('fontface') or ''
65 | self.fontsize = get_int_opt(options, 'fontsize', 0)
66 |
67 | def _escape(self, text):
68 | return text.replace(u'\\', u'\\\\') \
69 | .replace(u'{', u'\\{') \
70 | .replace(u'}', u'\\}')
71 |
72 | def _escape_text(self, text):
73 | # empty strings, should give a small performance improvment
74 | if not text:
75 | return u''
76 |
77 | # escape text
78 | text = self._escape(text)
79 |
80 | buf = []
81 | for c in text:
82 | cn = ord(c)
83 | if cn < (2**7):
84 | # ASCII character
85 | buf.append(str(c))
86 | elif (2**7) <= cn < (2**16):
87 | # single unicode escape sequence
88 | buf.append(u'{\\u%d}' % cn)
89 | elif (2**16) <= cn:
90 | # RTF limits unicode to 16 bits.
91 | # Force surrogate pairs
92 | buf.append(u'{\\u%d}{\\u%d}' % _surrogatepair(cn))
93 |
94 | return u''.join(buf).replace(u'\n', u'\\par\n')
95 |
96 | def format_unencoded(self, tokensource, outfile):
97 | # rtf 1.8 header
98 | outfile.write(u'{\\rtf1\\ansi\\uc0\\deff0'
99 | u'{\\fonttbl{\\f0\\fmodern\\fprq1\\fcharset0%s;}}'
100 | u'{\\colortbl;' % (self.fontface and
101 | u' ' + self._escape(self.fontface) or
102 | u''))
103 |
104 | # convert colors and save them in a mapping to access them later.
105 | color_mapping = {}
106 | offset = 1
107 | for _, style in self.style:
108 | for color in style['color'], style['bgcolor'], style['border']:
109 | if color and color not in color_mapping:
110 | color_mapping[color] = offset
111 | outfile.write(u'\\red%d\\green%d\\blue%d;' % (
112 | int(color[0:2], 16),
113 | int(color[2:4], 16),
114 | int(color[4:6], 16)
115 | ))
116 | offset += 1
117 | outfile.write(u'}\\f0 ')
118 | if self.fontsize:
119 | outfile.write(u'\\fs%d' % (self.fontsize))
120 |
121 | # highlight stream
122 | for ttype, value in tokensource:
123 | while not self.style.styles_token(ttype) and ttype.parent:
124 | ttype = ttype.parent
125 | style = self.style.style_for_token(ttype)
126 | buf = []
127 | if style['bgcolor']:
128 | buf.append(u'\\cb%d' % color_mapping[style['bgcolor']])
129 | if style['color']:
130 | buf.append(u'\\cf%d' % color_mapping[style['color']])
131 | if style['bold']:
132 | buf.append(u'\\b')
133 | if style['italic']:
134 | buf.append(u'\\i')
135 | if style['underline']:
136 | buf.append(u'\\ul')
137 | if style['border']:
138 | buf.append(u'\\chbrdr\\chcfpat%d' %
139 | color_mapping[style['border']])
140 | start = u''.join(buf)
141 | if start:
142 | outfile.write(u'{%s ' % start)
143 | outfile.write(self._escape_text(value))
144 | if start:
145 | outfile.write(u'}')
146 |
147 | outfile.write(u'}')
148 |
--------------------------------------------------------------------------------
/DrawBot.glyphsPlugin/Contents/Resources/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-2014 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 ``