1
"""
2
Extensions
3
-----------------------------------------------------------------------------
4
"""
5
6
class Extension:
7
    """ Base class for extensions to subclass. """
8
    def __init__(self, configs = {}):
9
        """Create an instance of an Extention.
10
11
        Keyword arguments:
12
13
        * configs: A dict of configuration setting used by an Extension.
14
        """
15
        self.config = configs
16
17
    def getConfig(self, key):
18
        """ Return a setting for the given key or an empty string. """
19
        if key in self.config:
20
            return self.config[key][0]
21
        else:
22
            return ""
23
24
    def getConfigInfo(self):
25
        """ Return all config settings as a list of tuples. """
26
        return [(key, self.config[key][1]) for key in self.config.keys()]
27
28
    def setConfig(self, key, value):
29
        """ Set a config setting for `key` with the given `value`. """
30
        self.config[key][0] = value
31
32
    def extendMarkdown(self, md, md_globals):
33
        """
34
        Add the various proccesors and patterns to the Markdown Instance.
35
36
        This method must be overriden by every extension.
37
38
        Keyword arguments:
39
40
        * md: The Markdown instance.
41
42
        * md_globals: Global variables in the markdown module namespace.
43
44
        """
45
        raise NotImplementedError, 'Extension "%s.%s" must define an "extendMarkdown"' \
46
            'method.' % (self.__class__.__module__, self.__class__.__name__)