__init__.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.styles
  4. ~~~~~~~~~~~~~~~
  5. Contains built-in styles.
  6. :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
  7. :license: BSD, see LICENSE for details.
  8. """
  9. from pygments.plugin import find_plugin_styles
  10. from pygments.util import ClassNotFound
  11. #: Maps style names to 'submodule::classname'.
  12. STYLE_MAP = {
  13. 'default': 'default::DefaultStyle',
  14. 'emacs': 'emacs::EmacsStyle',
  15. 'friendly': 'friendly::FriendlyStyle',
  16. 'colorful': 'colorful::ColorfulStyle',
  17. 'autumn': 'autumn::AutumnStyle',
  18. 'murphy': 'murphy::MurphyStyle',
  19. 'manni': 'manni::ManniStyle',
  20. 'monokai': 'monokai::MonokaiStyle',
  21. 'perldoc': 'perldoc::PerldocStyle',
  22. 'pastie': 'pastie::PastieStyle',
  23. 'borland': 'borland::BorlandStyle',
  24. 'trac': 'trac::TracStyle',
  25. 'native': 'native::NativeStyle',
  26. 'fruity': 'fruity::FruityStyle',
  27. 'bw': 'bw::BlackWhiteStyle',
  28. 'vim': 'vim::VimStyle',
  29. 'vs': 'vs::VisualStudioStyle',
  30. 'tango': 'tango::TangoStyle',
  31. 'rrt': 'rrt::RrtStyle',
  32. 'xcode': 'xcode::XcodeStyle',
  33. 'igor': 'igor::IgorStyle',
  34. 'paraiso-light': 'paraiso_light::ParaisoLightStyle',
  35. 'paraiso-dark': 'paraiso_dark::ParaisoDarkStyle',
  36. 'lovelace': 'lovelace::LovelaceStyle',
  37. 'algol': 'algol::AlgolStyle',
  38. 'algol_nu': 'algol_nu::Algol_NuStyle',
  39. 'arduino': 'arduino::ArduinoStyle',
  40. 'rainbow_dash': 'rainbow_dash::RainbowDashStyle',
  41. 'abap': 'abap::AbapStyle',
  42. 'solarized-dark': 'solarized::SolarizedDarkStyle',
  43. 'solarized-light': 'solarized::SolarizedLightStyle',
  44. 'sas': 'sas::SasStyle',
  45. 'stata': 'stata_light::StataLightStyle',
  46. 'stata-light': 'stata_light::StataLightStyle',
  47. 'stata-dark': 'stata_dark::StataDarkStyle',
  48. 'inkpot': 'inkpot::InkPotStyle',
  49. }
  50. def get_style_by_name(name):
  51. if name in STYLE_MAP:
  52. mod, cls = STYLE_MAP[name].split('::')
  53. builtin = "yes"
  54. else:
  55. for found_name, style in find_plugin_styles():
  56. if name == found_name:
  57. return style
  58. # perhaps it got dropped into our styles package
  59. builtin = ""
  60. mod = name
  61. cls = name.title() + "Style"
  62. try:
  63. mod = __import__('pygments.styles.' + mod, None, None, [cls])
  64. except ImportError:
  65. raise ClassNotFound("Could not find style module %r" % mod +
  66. (builtin and ", though it should be builtin") + ".")
  67. try:
  68. return getattr(mod, cls)
  69. except AttributeError:
  70. raise ClassNotFound("Could not find style class %r in style module." % cls)
  71. def get_all_styles():
  72. """Return an generator for all styles by name,
  73. both builtin and plugin."""
  74. for name in STYLE_MAP:
  75. yield name
  76. for name, _ in find_plugin_styles():
  77. yield name