aboutsummaryrefslogtreecommitdiffstats
path: root/markdown/extensions/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'markdown/extensions/__init__.py')
-rw-r--r--markdown/extensions/__init__.py36
1 files changed, 29 insertions, 7 deletions
diff --git a/markdown/extensions/__init__.py b/markdown/extensions/__init__.py
index 184c4d1..296ce0c 100644
--- a/markdown/extensions/__init__.py
+++ b/markdown/extensions/__init__.py
@@ -7,14 +7,28 @@ from __future__ import unicode_literals
class Extension(object):
""" Base class for extensions to subclass. """
- def __init__(self, configs = {}):
- """Create an instance of an Extention.
+
+ # Default config -- to be overriden by a subclass
+ # Must be of the following format:
+ # {
+ # 'key': ['value', 'description']
+ # }
+ # Note that Extension.setConfig will raise a KeyError
+ # if a default is not set here.
+ config = {}
+
+ def __init__(self, *args, **kwargs):
+ """ Initiate Extension and set up configs. """
- Keyword arguments:
-
- * configs: A dict of configuration setting used by an Extension.
- """
- self.config = configs
+ # check for configs arg for backward compat.
+ # (there only ever used to be one so we use arg[0])
+ if len(args):
+ self.setConfigs(args[0])
+ # check for configs kwarg for backward compat.
+ self.setConfigs(kwargs.pop('configs', {}))
+ # finally, use kwargs
+ self.setConfigs(kwargs)
+
def getConfig(self, key, default=''):
""" Return a setting for the given key or an empty string. """
@@ -35,6 +49,14 @@ class Extension(object):
""" Set a config setting for `key` with the given `value`. """
self.config[key][0] = value
+ def setConfigs(self, items):
+ """ Set multiple config settings given a dict or list of tuples. """
+ if hasattr(items, 'items'):
+ # it's a dict
+ items = items.items()
+ for key, value in items:
+ self.setConfig(key, value)
+
def extendMarkdown(self, md, md_globals):
"""
Add the various proccesors and patterns to the Markdown Instance.