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