You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.7 KiB

4 years ago
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.plugin
  4. ~~~~~~~~~~~~~~~
  5. Pygments setuptools plugin interface. The methods defined
  6. here also work if setuptools isn't installed but they just
  7. return nothing.
  8. lexer plugins::
  9. [pygments.lexers]
  10. yourlexer = yourmodule:YourLexer
  11. formatter plugins::
  12. [pygments.formatters]
  13. yourformatter = yourformatter:YourFormatter
  14. /.ext = yourformatter:YourFormatter
  15. As you can see, you can define extensions for the formatter
  16. with a leading slash.
  17. syntax plugins::
  18. [pygments.styles]
  19. yourstyle = yourstyle:YourStyle
  20. filter plugin::
  21. [pygments.filter]
  22. yourfilter = yourfilter:YourFilter
  23. :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
  24. :license: BSD, see LICENSE for details.
  25. """
  26. LEXER_ENTRY_POINT = 'pygments.lexers'
  27. FORMATTER_ENTRY_POINT = 'pygments.formatters'
  28. STYLE_ENTRY_POINT = 'pygments.styles'
  29. FILTER_ENTRY_POINT = 'pygments.filters'
  30. def iter_entry_points(group_name):
  31. try:
  32. import pkg_resources
  33. except (ImportError, IOError):
  34. return []
  35. return pkg_resources.iter_entry_points(group_name)
  36. def find_plugin_lexers():
  37. for entrypoint in iter_entry_points(LEXER_ENTRY_POINT):
  38. yield entrypoint.load()
  39. def find_plugin_formatters():
  40. for entrypoint in iter_entry_points(FORMATTER_ENTRY_POINT):
  41. yield entrypoint.name, entrypoint.load()
  42. def find_plugin_styles():
  43. for entrypoint in iter_entry_points(STYLE_ENTRY_POINT):
  44. yield entrypoint.name, entrypoint.load()
  45. def find_plugin_filters():
  46. for entrypoint in iter_entry_points(FILTER_ENTRY_POINT):
  47. yield entrypoint.name, entrypoint.load()