Back to index

moin  1.9.0~rc2
_mapping.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 """
00003     pygments.formatters._mapping
00004     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
00005 
00006     Formatter mapping defintions. This file is generated by itself. Everytime
00007     you change something on a builtin formatter defintion, run this script from
00008     the formatters folder to update it.
00009 
00010     Do not alter the FORMATTERS dictionary by hand.
00011 
00012     :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS.
00013     :license: BSD, see LICENSE for details.
00014 """
00015 
00016 from pygments.util import docstring_headline
00017 
00018 # start
00019 from pygments.formatters.bbcode import BBCodeFormatter
00020 from pygments.formatters.html import HtmlFormatter
00021 from pygments.formatters.img import BmpImageFormatter
00022 from pygments.formatters.img import GifImageFormatter
00023 from pygments.formatters.img import ImageFormatter
00024 from pygments.formatters.img import JpgImageFormatter
00025 from pygments.formatters.latex import LatexFormatter
00026 from pygments.formatters.other import NullFormatter
00027 from pygments.formatters.other import RawTokenFormatter
00028 from pygments.formatters.rtf import RtfFormatter
00029 from pygments.formatters.svg import SvgFormatter
00030 from pygments.formatters.terminal import TerminalFormatter
00031 from pygments.formatters.terminal256 import Terminal256Formatter
00032 
00033 FORMATTERS = {
00034     BBCodeFormatter: ('BBCode', ('bbcode', 'bb'), (), 'Format tokens with BBcodes. These formatting codes are used by many bulletin boards, so you can highlight your sourcecode with pygments before posting it there.'),
00035     BmpImageFormatter: ('img_bmp', ('bmp', 'bitmap'), ('*.bmp',), 'Create a bitmap image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
00036     GifImageFormatter: ('img_gif', ('gif',), ('*.gif',), 'Create a GIF image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
00037     HtmlFormatter: ('HTML', ('html',), ('*.html', '*.htm'), "Format tokens as HTML 4 ``<span>`` tags within a ``<pre>`` tag, wrapped in a ``<div>`` tag. The ``<div>``'s CSS class can be set by the `cssclass` option."),
00038     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.'),
00039     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.'),
00040     LatexFormatter: ('LaTeX', ('latex', 'tex'), ('*.tex',), 'Format tokens as LaTeX code. This needs the `fancyvrb` and `color` standard packages.'),
00041     NullFormatter: ('Text only', ('text', 'null'), ('*.txt',), 'Output the text unchanged without any formatting.'),
00042     RawTokenFormatter: ('Raw tokens', ('raw', 'tokens'), ('*.raw',), 'Format tokens as a raw representation for storing token streams.'),
00043     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.'),
00044     SvgFormatter: ('SVG', ('svg',), ('*.svg',), 'Format tokens as an SVG graphics file.  This formatter is still experimental. Each line of code is a ``<text>`` element with explicit ``x`` and ``y`` coordinates containing ``<tspan>`` elements with the individual token styles.'),
00045     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.'),
00046     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.')
00047 }
00048 
00049 if __name__ == '__main__':
00050     import sys
00051     import os
00052 
00053     # lookup formatters
00054     found_formatters = []
00055     imports = []
00056     sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
00057     for filename in os.listdir('.'):
00058         if filename.endswith('.py') and not filename.startswith('_'):
00059             module_name = 'pygments.formatters.%s' % filename[:-3]
00060             print module_name
00061             module = __import__(module_name, None, None, [''])
00062             for formatter_name in module.__all__:
00063                 imports.append((module_name, formatter_name))
00064                 formatter = getattr(module, formatter_name)
00065                 found_formatters.append(
00066                     '%s: %r' % (formatter_name,
00067                                 (formatter.name,
00068                                  tuple(formatter.aliases),
00069                                  tuple(formatter.filenames),
00070                                  docstring_headline(formatter))))
00071     # sort them, that should make the diff files for svn smaller
00072     found_formatters.sort()
00073     imports.sort()
00074 
00075     # extract useful sourcecode from this file
00076     f = open(__file__)
00077     try:
00078         content = f.read()
00079     finally:
00080         f.close()
00081     header = content[:content.find('# start')]
00082     footer = content[content.find("if __name__ == '__main__':"):]
00083 
00084     # write new file
00085     f = open(__file__, 'w')
00086     f.write(header)
00087     f.write('# start\n')
00088     f.write('\n'.join(['from %s import %s' % imp for imp in imports]))
00089     f.write('\n\n')
00090     f.write('FORMATTERS = {\n    %s\n}\n\n' % ',\n    '.join(found_formatters))
00091     f.write(footer)
00092     f.close()