/
usr
/
lib
/
python2.6
/
site-packages
/
markdown
/
extensions
/
/usr/lib/python2.6/site-packages/markdown/extensions
mkdir
upload
Name
Size
Mode
Actions
abbr.py
2899
0644
edit
dl
rm
abbr.pyc
4294
0644
edit
dl
rm
abbr.pyo
4294
0644
edit
dl
rm
codehilite.py
7673
0644
edit
dl
rm
codehilite.pyc
8129
0644
edit
dl
rm
codehilite.pyo
8129
0644
edit
dl
rm
def_list.py
3170
0644
edit
dl
rm
def_list.pyc
4047
0644
edit
dl
rm
def_list.pyo
4047
0644
edit
dl
rm
extra.py
1739
0644
edit
dl
rm
extra.pyc
2323
0644
edit
dl
rm
extra.pyo
2323
0644
edit
dl
rm
fenced_code.py
3423
0644
edit
dl
rm
fenced_code.pyc
4371
0644
edit
dl
rm
fenced_code.pyo
4371
0644
edit
dl
rm
footnotes.py
10055
0644
edit
dl
rm
footnotes.pyc
11433
0644
edit
dl
rm
footnotes.pyo
11433
0644
edit
dl
rm
headerid.py
6326
0644
edit
dl
rm
headerid.pyc
7470
0644
edit
dl
rm
headerid.pyo
7470
0644
edit
dl
rm
html_tidy.py
2071
0644
edit
dl
rm
html_tidy.pyc
2756
0644
edit
dl
rm
html_tidy.pyo
2756
0644
edit
dl
rm
imagelinks.py
3491
0644
edit
dl
rm
imagelinks.pyc
3311
0644
edit
dl
rm
imagelinks.pyo
3311
0644
edit
dl
rm
meta.py
2590
0644
edit
dl
rm
meta.pyc
3275
0644
edit
dl
rm
meta.pyo
3275
0644
edit
dl
rm
rss.py
3693
0644
edit
dl
rm
rss.pyc
4337
0644
edit
dl
rm
rss.pyo
4337
0644
edit
dl
rm
tables.py
3079
0644
edit
dl
rm
tables.pyc
3877
0644
edit
dl
rm
tables.pyo
3877
0644
edit
dl
rm
toc.py
5098
0644
edit
dl
rm
toc.pyc
4466
0644
edit
dl
rm
toc.pyo
4466
0644
edit
dl
rm
wikilinks.py
5292
0644
edit
dl
rm
wikilinks.pyc
6281
0644
edit
dl
rm
wikilinks.pyo
6281
0644
edit
dl
rm
__init__.py
0
0644
edit
dl
rm
__init__.pyc
151
0644
edit
dl
rm
__init__.pyo
151
0644
edit
dl
rm
Edit:
/usr/lib/python2.6/site-packages/markdown/extensions/wikilinks.py
(5292B)
''' WikiLinks Extension for Python-Markdown ====================================== Converts [[WikiLinks]] to relative links. Requires Python-Markdown 2.0+ Basic usage: >>> import markdown >>> text = "Some text with a [[WikiLink]]." >>> html = markdown.markdown(text, ['wikilinks']) >>> html u'<p>Some text with a <a class="wikilink" href="/WikiLink/">WikiLink</a>.</p>' Whitespace behavior: >>> markdown.markdown('[[ foo bar_baz ]]', ['wikilinks']) u'<p><a class="wikilink" href="/foo_bar_baz/">foo bar_baz</a></p>' >>> markdown.markdown('foo [[ ]] bar', ['wikilinks']) u'<p>foo bar</p>' To define custom settings the simple way: >>> markdown.markdown(text, ... ['wikilinks(base_url=/wiki/,end_url=.html,html_class=foo)'] ... ) u'<p>Some text with a <a class="foo" href="/wiki/WikiLink.html">WikiLink</a>.</p>' Custom settings the complex way: >>> md = markdown.Markdown( ... extensions = ['wikilinks'], ... extension_configs = {'wikilinks': [ ... ('base_url', 'http://example.com/'), ... ('end_url', '.html'), ... ('html_class', '') ]}, ... safe_mode = True) >>> md.convert(text) u'<p>Some text with a <a href="http://example.com/WikiLink.html">WikiLink</a>.</p>' 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', 'wikilinks']) >>> md.convert(text) u'<p>Some text with a <a href="http://example.com/WikiLink.html">WikiLink</a>.</p>' MetaData should not carry over to next document: >>> md.convert("No [[MetaData]] here.") u'<p>No <a class="wikilink" href="/MetaData/">MetaData</a> here.</p>' Define a custom URL builder: >>> def my_url_builder(label, base, end): ... return '/bar/' >>> md = markdown.Markdown(extensions=['wikilinks'], ... extension_configs={'wikilinks' : [('build_url', my_url_builder)]}) >>> md.convert('[[foo]]') u'<p><a class="wikilink" href="/bar/">foo</a></p>' From the command line: python markdown.py -x wikilinks(base_url=http://example.com/,end_url=.html,html_class=foo) src.txt By [Waylan Limberg](http://achinghead.com/). License: [BSD](http://www.opensource.org/licenses/bsd-license.php) Dependencies: * [Python 2.3+](http://python.org) * [Markdown 2.0+](http://www.freewisdom.org/projects/python-markdown/) ''' import markdown import re def build_url(label, base, end): """ Build a url from the label, a base, and an end. """ clean_label = re.sub(r'([ ]+_)|(_[ ]+)|([ ]+)', '_', label) return '%s%s%s'% (base, clean_label, end) 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.'], 'build_url' : [build_url, 'Callable formats URL from label.'], } # 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'\[\[([A-Za-z0-9_ -]+)\]\]' wikilinkPattern = WikiLinks(WIKILINK_RE, self.config) wikilinkPattern.md = md md.inlinePatterns.add('wikilink', wikilinkPattern, "<not_strong") class WikiLinks(markdown.inlinepatterns.Pattern): def __init__(self, pattern, config): markdown.inlinepatterns.Pattern.__init__(self, pattern) self.config = config def handleMatch(self, m): if m.group(2).strip(): base_url, end_url, html_class = self._getMeta() label = m.group(2).strip() url = self.config['build_url'][0](label, base_url, end_url) a = markdown.etree.Element('a') a.text = label a.set('href', url) if html_class: a.set('class', html_class) else: a = '' 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 makeExtension(configs=None) : return WikiLinkExtension(configs=configs) if __name__ == "__main__": import doctest doctest.testmod()
Save
cmd:
run