Back to index

moin  1.9.0~rc2
plugin.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 """
00003     pygments.plugin
00004     ~~~~~~~~~~~~~~~
00005 
00006     Pygments setuptools plugin interface. The methods defined
00007     here also work if setuptools isn't installed but they just
00008     return nothing.
00009 
00010     lexer plugins::
00011 
00012         [pygments.lexers]
00013         yourlexer = yourmodule:YourLexer
00014 
00015     formatter plugins::
00016 
00017         [pygments.formatters]
00018         yourformatter = yourformatter:YourFormatter
00019         /.ext = yourformatter:YourFormatter
00020 
00021     As you can see, you can define extensions for the formatter
00022     with a leading slash.
00023 
00024     syntax plugins::
00025 
00026         [pygments.styles]
00027         yourstyle = yourstyle:YourStyle
00028 
00029     filter plugin::
00030 
00031         [pygments.filter]
00032         yourfilter = yourfilter:YourFilter
00033 
00034 
00035     :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS.
00036     :license: BSD, see LICENSE for details.
00037 """
00038 try:
00039     import pkg_resources
00040 except ImportError:
00041     pkg_resources = None
00042 
00043 LEXER_ENTRY_POINT = 'pygments.lexers'
00044 FORMATTER_ENTRY_POINT = 'pygments.formatters'
00045 STYLE_ENTRY_POINT = 'pygments.styles'
00046 FILTER_ENTRY_POINT = 'pygments.filters'
00047 
00048 
00049 def find_plugin_lexers():
00050     if pkg_resources is None:
00051         return
00052     for entrypoint in pkg_resources.iter_entry_points(LEXER_ENTRY_POINT):
00053         yield entrypoint.load()
00054 
00055 
00056 def find_plugin_formatters():
00057     if pkg_resources is None:
00058         return
00059     for entrypoint in pkg_resources.iter_entry_points(FORMATTER_ENTRY_POINT):
00060         yield entrypoint.name, entrypoint.load()
00061 
00062 
00063 def find_plugin_styles():
00064     if pkg_resources is None:
00065         return
00066     for entrypoint in pkg_resources.iter_entry_points(STYLE_ENTRY_POINT):
00067         yield entrypoint.name, entrypoint.load()
00068 
00069 
00070 def find_plugin_filters():
00071     if pkg_resources is None:
00072         return
00073     for entrypoint in pkg_resources.iter_entry_points(FILTER_ENTRY_POINT):
00074         yield entrypoint.name, entrypoint.load()