From 2b7e391fcd51d3468133f628f2e013574cf16536 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Sat, 9 Aug 2008 22:55:44 -0400 Subject: reorganized the extensions into a seperate dir. Much cleaner looking file system IMO. --- mdx_wikilink.py | 140 -------------------------------------------------------- 1 file changed, 140 deletions(-) delete mode 100644 mdx_wikilink.py (limited to 'mdx_wikilink.py') diff --git a/mdx_wikilink.py b/mdx_wikilink.py deleted file mode 100644 index 47037a6..0000000 --- a/mdx_wikilink.py +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env python - -''' -WikiLink Extention for Python-Markdown -====================================== - -Converts CamelCase words to relative links. Requires Python-Markdown 1.6+ - -Basic usage: - - >>> import markdown - >>> text = "Some text with a WikiLink." - >>> md = markdown.markdown(text, ['wikilink']) - >>> md - u'

Some text with a WikiLink.\\n

' - -To define custom settings the simple way: - - >>> md = markdown.markdown(text, - ... ['wikilink(base_url=/wiki/,end_url=.html,html_class=foo)'] - ... ) - >>> md - u'

Some text with a WikiLink.\\n

' - -Custom settings the complex way: - - >>> md = markdown.Markdown( - ... extensions = ['wikilink'], - ... extension_configs = {'wikilink': [ - ... ('base_url', 'http://example.com/'), - ... ('end_url', '.html'), - ... ('html_class', '') ]}, - ... safe_mode = True) - >>> md.convert(text) - u'

Some text with a WikiLink.\\n

' - -Use MetaData with mdx_meta.py (Note the blank html_class in MetaData): - - >>> text = """wiki_base_url: http://example.com/ - ... wiki_end_url: .html - ... wiki_html_class: - ... - ... Some text with a WikiLink.""" - >>> md = markdown.Markdown(extensions=['meta', 'wikilink']) - >>> md.convert(text) - u'

Some text with a WikiLink.\\n

' - -MetaData should not carry over to next document: - - >>> md.convert("No MetaData here.") - u'

No MetaData here.\\n

' - -From the command line: - - python markdown.py -x wikilink(base_url=http://example.com/,end_url=.html,html_class=foo) src.txt - -By [Waylan Limberg](http://achinghead.com/). - -Project website: http://achinghead.com/markdown-wikilinks/ -Contact: waylan [at] gmail [dot] com - -License: [BSD](http://www.opensource.org/licenses/bsd-license.php) - -Version: 0.6 (May 2, 2008) - -Dependencies: -* [Python 2.3+](http://python.org) -* [Markdown 1.6+](http://www.freewisdom.org/projects/python-markdown/) -''' - -import markdown -from markdown import etree - -class WikiLinkExtension (markdown.Extension) : - def __init__(self, configs): - # set extension defaults - self.config = { - 'base_url' : ['/', 'String to append to beginning or URL.'], - 'end_url' : ['/', 'String to append to end of URL.'], - 'html_class' : ['wikilink', 'CSS hook. Leave blank for none.'] - } - - # Override defaults with user settings - for key, value in configs : - self.setConfig(key, value) - - def extendMarkdown(self, md, md_globals): - self.md = md - - # append to end of inline patterns - WIKILINK_RE = r'''(?P\\|\b)(?P([A-Z]+[a-z-_]+){2,})\b''' - WIKILINK_PATTERN = WikiLinks(WIKILINK_RE, self.config) - WIKILINK_PATTERN.md = md - md.inlinePatterns.append(WIKILINK_PATTERN) - - -class WikiLinks (markdown.BasePattern) : - def __init__(self, pattern, config): - markdown.BasePattern.__init__(self, pattern) - self.config = config - - def handleMatch(self, m): - if m.group('escape') == '\\': - a = m.group('camelcase') - else: - base_url, end_url, html_class = self._getMeta() - url = '%s%s%s'% (base_url, m.group('camelcase'), end_url) - label = m.group('camelcase').replace('_', ' ') - a = etree.Element('a') - a.text = label - a.set('href', url) - if html_class: - a.set('class', html_class) - return a - - def _getMeta(self): - """ Return meta data or config data. """ - base_url = self.config['base_url'][0] - end_url = self.config['end_url'][0] - html_class = self.config['html_class'][0] - if hasattr(self.md, 'Meta'): - if self.md.Meta.has_key('wiki_base_url'): - base_url = self.md.Meta['wiki_base_url'][0] - if self.md.Meta.has_key('wiki_end_url'): - end_url = self.md.Meta['wiki_end_url'][0] - if self.md.Meta.has_key('wiki_html_class'): - html_class = self.md.Meta['wiki_html_class'][0] - return base_url, end_url, html_class - - def type(self): - return "WLink" - - -def makeExtension(configs=None) : - return WikiLinkExtension(configs=configs) - -if __name__ == "__main__": - import doctest - doctest.testmod() - -- cgit v1.2.3