Current File : //usr/share/doc/python2-markdown-2.4.1/extensions/wikilinks.html |
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>WikiLinks Extension — Python Markdown</title>
<link rel="stylesheet" href="../default.css" type="text/css">
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../siteindex.html" title="General Index">index</a></li>
<li class="right">
<a href="api.html" title="Extension API"
accesskey="N">next</a> |</li>
<li class="right">
<a href="toc.html" title="Table of Contents Extension"
accesskey="P">previous</a> |</li>
<li><img src="../py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="../index.html">Python Markdown v2.4.1 documentation</a> »</li>
<li><a href="index.html">Extensions</a> »</li>
<li><a href="wikilinks.html">WikiLinks Extension</a> »</li>
</ul>
</div> <!-- .related -->
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<h1 id="wikilinks">WikiLinks<a class="headerlink" href="#wikilinks" title="Permanent link">¶</a></h1>
<h2 id="summary">Summary<a class="headerlink" href="#summary" title="Permanent link">¶</a></h2>
<p>The WikiLinks extension adds support for <a href="http://en.wikipedia.org/wiki/Wikilink">WikiLinks</a>. Specifically, any
<code>[[bracketed]]</code> word is converted to a link.</p>
<p>This extension is included in the standard Markdown library.</p>
<h2 id="syntax">Syntax<a class="headerlink" href="#syntax" title="Permanent link">¶</a></h2>
<p>A <code>[[bracketed]]</code> word is any combination of upper or lower case letters,
number, dashes, underscores and spaces surrounded by double brackets. Therefore</p>
<pre><code>[[Bracketed]]
</code></pre>
<p>would produce the following html:</p>
<pre><code><a href="/Bracketed/" class="wikilink">Bracketed</a>
</code></pre>
<p>Note that wikilinks are automatically assigned <code>class="wikilink"</code> making it
easy to style wikilinks differently from other links on a page if one so
desires. See below for ways to alter the class.</p>
<p>Also note that when a space is used, the space is converted to an underscore in
the link but left as-is in the label. Perhaps an example would illustrate this
best:</p>
<pre><code>[[Wiki Link]]
</code></pre>
<p>becomes</p>
<pre><code><a href="/Wiki_Link/" class="wikilink">Wiki Link</a>
</code></pre>
<h2 id="usage">Usage<a class="headerlink" href="#usage" title="Permanent link">¶</a></h2>
<p>See <a href="index.html">Extensions</a> for general extension usage, specify <code>wikilinks</code>
as the name of the extension.</p>
<p>See the <a href="../reference.html#extensions">Library Reference</a> for information about
configuring extensions.</p>
<p>The default behavior is to point each link to the document root of the current
domain and close with a trailing slash. Additionally, each link is assigned to
the html class <code>wikilink</code>.</p>
<p>The following options are provided to change the default behavior:</p>
<ul>
<li>
<p><strong><code>base_url</code></strong>: String to append to beginning of URL.</p>
<p>Default: <code>'/'</code></p>
</li>
<li>
<p><strong><code>end_url</code></strong>: String to append to end of URL.</p>
<p>Default: <code>'/'</code></p>
</li>
<li>
<p><strong><code>html_class</code></strong>: CSS class. Leave blank for none.</p>
<p>Default: <code>'wikilink'</code></p>
</li>
<li>
<p><strong><code>build_url</code></strong>: Callable which formats the URL from its parts.</p>
</li>
</ul>
<h3 id="examples">Examples<a class="headerlink" href="#examples" title="Permanent link">¶</a></h3>
<p>For an example, let us suppose links should always point to the subdirectory
<code>/wiki/</code> and end with <code>.html</code></p>
<pre><code>>>> html = markdown.markdown(text,
... ['wikilinks(base_url=/wiki/,end_url=.html)']
... )
</code></pre>
<p>The above would result in the following link for <code>[[WikiLink]]</code>.</p>
<pre><code><a href="/wiki/WikiLink.html" class="wikilink">WikiLink</a>
</code></pre>
<p>If you want to do more that just alter the base and/or end of the URL, you
could also pass in a callable which must accept three arguments (<code>label</code>,
<code>base</code>, and <code>end</code>). The callable must return the URL in it’s entirety.</p>
<pre><code>def my_url_builder(label, base, end):
# do stuff
return url
md = markdown.Markdown(
extensions=['wikilinks],
extension_configs={'wikilinks' : [('build_url', my_url_builder)]}
)
</code></pre>
<p>The option is also provided to change or remove the class attribute.</p>
<pre><code>>>> html = markdown.markdown(text,
... ['wikilinks(html_class=myclass)']
... )
</code></pre>
<p>Would cause all wikilinks to be assigned to the class <code>myclass</code>.</p>
<pre><code><a href="/WikiLink/" class="myclass">WikiLink</a>
</code></pre>
<h2 id="using-with-meta-data-extension">Using with Meta-Data extension<a class="headerlink" href="#using-with-meta-data-extension" title="Permanent link">¶</a></h2>
<p>The WikiLink extension also supports the <a href="meta_data.html">Meta-Data</a> extension.
Please see the documentation for that extension for specifics. The supported
meta-data keywords are:</p>
<ul>
<li><code>wiki_base_url</code></li>
<li><code>wiki_end_url</code></li>
<li><code>wiki_html_class</code></li>
</ul>
<p>When used, the meta-data will override the settings provided through the
<code>extension_configs</code> interface.</p>
<p>This document:</p>
<pre><code>wiki_base_url: http://example.com/
wiki_end_url: .html
wiki_html_class:
A [[WikiLink]] in the first paragraph.
</code></pre>
<p>would result in the following output (notice the blank <code>wiki_html_class</code>):</p>
<pre><code><p>A <a href="http://example.com/WikiLink.html">WikiLink</a> in the first paragraph.</p>
</code></pre>
</div> <!-- .body -->
</div> <!-- .bodywrapper -->
</div> <!-- .documentwrapper -->
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3>Table Of Contents</h3>
<div class="toc">
<ul>
<li><a href="#wikilinks">WikiLinks</a><ul>
<li><a href="#summary">Summary</a></li>
<li><a href="#syntax">Syntax</a></li>
<li><a href="#usage">Usage</a><ul>
<li><a href="#examples">Examples</a></li>
</ul>
</li>
<li><a href="#using-with-meta-data-extension">Using with Meta-Data extension</a></li>
</ul>
</li>
</ul>
</div>
<h4>Previous topic</h4>
<p class="topless"><a href="toc.html"
title="previous chapter">Table of Contents Extension</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="api.html"
title="next chapter">Extension API</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="https://github.com/waylan/Python-Markdown/issues"
>Report a Bug</a></li>
<li><a href="wikilinks.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div> <!-- .sphinxsidebarwrapper -->
</div> <!-- .sphinxsidebar -->
<div class="clearer"></div>
</div> <!-- .document -->
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../siteindex.html" title="General Index">index</a></li>
<li class="right">
<a href="api.html" title="Extension API"
accesskey="N">next</a> |</li>
<li class="right">
<a href="toc.html" title="Table of Contents Extension"
accesskey="P">previous</a> |</li>
<li><img src="../py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="../index.html">Python Markdown v2.4.1 documentation</a> »</li>
<li><a href="index.html">Extensions</a> »</li>
<li><a href="wikilinks.html">WikiLinks Extension</a> »</li>
</ul>
</div> <!-- .related -->
<div class="footer">© 2010-2012 Python Markdown Project</div>
</body>
</html>