15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# markdown is released under the BSD license 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# Copyright 2007, 2008 The Python Markdown Project (v. 1.7 and later) 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b) 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# Copyright 2004 Manfred Stienstra (the original version) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# All rights reserved. 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# Redistribution and use in source and binary forms, with or without 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# modification, are permitted provided that the following conditions are met: 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# * Redistributions of source code must retain the above copyright 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# notice, this list of conditions and the following disclaimer. 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# * Redistributions in binary form must reproduce the above copyright 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# notice, this list of conditions and the following disclaimer in the 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# documentation and/or other materials provided with the distribution. 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# * Neither the name of the <organization> nor the 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# names of its contributors may be used to endorse or promote products 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# derived from this software without specific prior written permission. 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# THIS SOFTWARE IS PROVIDED BY THE PYTHON MARKDOWN PROJECT ''AS IS'' AND ANY 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# DISCLAIMED. IN NO EVENT SHALL ANY CONTRIBUTORS TO THE PYTHON MARKDOWN PROJECT 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)# POSSIBILITY OF SUCH DAMAGE. 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)""" 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)Extensions 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)----------------------------------------------------------------------------- 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)""" 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)from __future__ import unicode_literals 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class Extension(object): 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) """ Base class for extensions to subclass. """ 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) def __init__(self, configs = {}): 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) """Create an instance of an Extention. 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Keyword arguments: 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * configs: A dict of configuration setting used by an Extension. 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) """ 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) self.config = configs 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) def getConfig(self, key, default=''): 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) """ Return a setting for the given key or an empty string. """ 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if key in self.config: 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return self.config[key][0] 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) else: 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return default 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) def getConfigs(self): 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) """ Return all configs settings as a dict. """ 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return dict([(key, self.getConfig(key)) for key in self.config.keys()]) 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) def getConfigInfo(self): 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) """ Return all config descriptions as a list of tuples. """ 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return [(key, self.config[key][1]) for key in self.config.keys()] 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) def setConfig(self, key, value): 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) """ Set a config setting for `key` with the given `value`. """ 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) self.config[key][0] = value 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) def extendMarkdown(self, md, md_globals): 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) """ 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Add the various proccesors and patterns to the Markdown Instance. 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) This method must be overriden by every extension. 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Keyword arguments: 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * md: The Markdown instance. 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * md_globals: Global variables in the markdown module namespace. 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) """ 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) raise NotImplementedError('Extension "%s.%s" must define an "extendMarkdown"' \ 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 'method.' % (self.__class__.__module__, self.__class__.__name__)) 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 86