summaryrefslogtreecommitdiff
path: root/pygments/styles/__init__.py
blob: c75493b47d3efbba8ed3ee4e4902e5d44f5b299c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
"""
    pygments.styles
    ~~~~~~~~~~~~~~~

    Contains built-in styles.

    :copyright: 2006 by Georg Brandl.
    :license: BSD, see LICENSE for more details.
"""
from pygments.plugin import find_plugin_styles


#: Maps style names to 'submodule::classname'.
STYLE_MAP = {
    'default':  'default::DefaultStyle',
    'emacs':    'default::DefaultStyle',
    'friendly': 'friendly::FriendlyStyle',
    'colorful': 'colorful::ColorfulStyle',
    'autumn':   'autumn::AutumnStyle',
    'murphy':   'murphy::MurphyStyle',
    'manni':    'manni::ManniStyle',
    'perldoc':  'perldoc::PerldocStyle',
    'pastie':   'pastie::PastieStyle',
    'borland':  'borland::BorlandStyle',
    'trac':     'trac::TracStyle',
    'native':   'native::NativeStyle',
    'fruity':   'fruity::FruityStyle'
}


def get_style_by_name(name):
    if name not in STYLE_MAP:
        for found_name, style in find_plugin_styles():
            if name == found_name:
                return style
        raise ValueError("Style %r not found" % name)

    mod, cls = STYLE_MAP[name].split('::')
    mod = __import__('pygments.styles.' + mod, None, None, [cls])
    return getattr(mod, cls)


def get_all_styles():
    """Return an generator for all styles by name.
    Both builtin and plugin."""
    for name in STYLE_MAP:
        yield name
    for name, _ in find_plugin_styles():
        yield name