1 # markdown is released under the BSD license
2 # Copyright 2007, 2008 The Python Markdown Project (v. 1.7 and later)
3 # Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b)
4 # Copyright 2004 Manfred Stienstra (the original version)
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # * Neither the name of the <organization> nor the
17 # names of its contributors may be used to endorse or promote products
18 # derived from this software without specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE PYTHON MARKDOWN PROJECT ''AS IS'' AND ANY
21 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 # DISCLAIMED. IN NO EVENT SHALL ANY CONTRIBUTORS TO THE PYTHON MARKDOWN PROJECT
24 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
35 -----------------------------------------------------------------------------
38 from __future__
import unicode_literals
40 class Extension(object):
41 """ Base class for extensions to subclass. """
42 def __init__(self
, configs
= {}):
43 """Create an instance of an Extention.
47 * configs: A dict of configuration setting used by an Extension.
51 def getConfig(self
, key
, default
=''):
52 """ Return a setting for the given key or an empty string. """
53 if key
in self
.config
:
54 return self
.config
[key
][0]
59 """ Return all configs settings as a dict. """
60 return dict([(key
, self
.getConfig(key
)) for key
in self
.config
.keys()])
62 def getConfigInfo(self
):
63 """ Return all config descriptions as a list of tuples. """
64 return [(key
, self
.config
[key
][1]) for key
in self
.config
.keys()]
66 def setConfig(self
, key
, value
):
67 """ Set a config setting for `key` with the given `value`. """
68 self
.config
[key
][0] = value
70 def extendMarkdown(self
, md
, md_globals
):
72 Add the various proccesors and patterns to the Markdown Instance.
74 This method must be overriden by every extension.
78 * md: The Markdown instance.
80 * md_globals: Global variables in the markdown module namespace.
83 raise NotImplementedError('Extension "%s.%s" must define an "extendMarkdown"' \
84 'method.' % (self
.__class
__.__module
__, self
.__class
__.__name
__))