|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.styles |
|
4 ~~~~~~~~~~~~~~~ |
|
5 |
|
6 Contains built-in styles. |
|
7 |
|
8 :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS. |
|
9 :license: BSD, see LICENSE for details. |
|
10 """ |
|
11 |
|
12 from pygments.plugin import find_plugin_styles |
|
13 from pygments.util import ClassNotFound |
|
14 |
|
15 |
|
16 #: Maps style names to 'submodule::classname'. |
|
17 STYLE_MAP = { |
|
18 'default': 'default::DefaultStyle', |
|
19 'emacs': 'emacs::EmacsStyle', |
|
20 'friendly': 'friendly::FriendlyStyle', |
|
21 'colorful': 'colorful::ColorfulStyle', |
|
22 'autumn': 'autumn::AutumnStyle', |
|
23 'murphy': 'murphy::MurphyStyle', |
|
24 'manni': 'manni::ManniStyle', |
|
25 'perldoc': 'perldoc::PerldocStyle', |
|
26 'pastie': 'pastie::PastieStyle', |
|
27 'borland': 'borland::BorlandStyle', |
|
28 'trac': 'trac::TracStyle', |
|
29 'native': 'native::NativeStyle', |
|
30 'fruity': 'fruity::FruityStyle', |
|
31 'bw': 'bw::BlackWhiteStyle', |
|
32 'vs': 'vs::VisualStudioStyle', |
|
33 'tango': 'tango::TangoStyle', |
|
34 } |
|
35 |
|
36 |
|
37 def get_style_by_name(name): |
|
38 if name in STYLE_MAP: |
|
39 mod, cls = STYLE_MAP[name].split('::') |
|
40 builtin = "yes" |
|
41 else: |
|
42 for found_name, style in find_plugin_styles(): |
|
43 if name == found_name: |
|
44 return style |
|
45 # perhaps it got dropped into our styles package |
|
46 builtin = "" |
|
47 mod = name |
|
48 cls = name.title() + "Style" |
|
49 |
|
50 try: |
|
51 mod = __import__('pygments.styles.' + mod, None, None, [cls]) |
|
52 except ImportError: |
|
53 raise ClassNotFound("Could not find style module %r" % mod + |
|
54 (builtin and ", though it should be builtin") + ".") |
|
55 try: |
|
56 return getattr(mod, cls) |
|
57 except AttributeError: |
|
58 raise ClassNotFound("Could not find style class %r in style module." % cls) |
|
59 |
|
60 |
|
61 def get_all_styles(): |
|
62 """Return an generator for all styles by name, |
|
63 both builtin and plugin.""" |
|
64 for name in STYLE_MAP: |
|
65 yield name |
|
66 for name, _ in find_plugin_styles(): |
|
67 yield name |