σ Šη\c@@s§dZddlmZddlmZddlmZddlmZddlm Z dd l Z d „Z d efd „ƒYZ d efd„ƒYZ d d„Zd S(ue 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']) >>> print html

Some text with a WikiLink.

Whitespace behavior: >>> print markdown.markdown('[[ foo bar_baz ]]', ['wikilinks'])

foo bar_baz

>>> print markdown.markdown('foo [[ ]] bar', ['wikilinks'])

foo bar

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

Some text with a WikiLink.

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) >>> print md.convert(text)

Some text with a WikiLink.

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']) >>> print md.convert(text)

Some text with a WikiLink.

MetaData should not carry over to next document: >>> print md.convert("No [[MetaData]] here.")

No MetaData here.

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)]}) >>> print md.convert('[[foo]]')

foo

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://packages.python.org/Markdown/) i(tabsolute_import(tunicode_literalsi(t Extensioni(tPattern(tetreeNcC@s&tjdd|ƒ}d|||fS(u1 Build a url from the label, a base, and an end. u([ ]+_)|(_[ ]+)|([ ]+)u_u%s%s%s(tretsub(tlabeltbasetendt clean_label((sA/usr/lib/python2.7/site-packages/markdown/extensions/wikilinks.pyt build_urlVstWikiLinkExtensioncB@seZd„Zd„ZRS(cC@s€iddgd6ddgd6ddgd6td gd 6|_t|ƒpLi}x*|jƒD]\}}|j||ƒq\WdS( Nu/u%String to append to beginning or URL.ubase_urluString to append to end of URL.uend_urluwikilinkuCSS hook. Leave blank for none.u html_classu Callable formats URL from label.u build_url(R tconfigtdicttitemst setConfig(tselftconfigstkeytvalue((sA/usr/lib/python2.7/site-packages/markdown/extensions/wikilinks.pyt__init__]s   cC@sG||_d}t||jƒƒ}||_|jjd|dƒdS(Nu\[\[([\w0-9_ -]+)\]\]uwikilinku Ms  "