aboutsummaryrefslogtreecommitdiffstats
path: root/markdown
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2009-03-20 21:33:23 -0400
committerWaylan Limberg <waylan@gmail.com>2009-03-20 21:33:23 -0400
commit834d1a8afe8236d60a994c649e453a650e7594a9 (patch)
treef4782cd1b1fb71aa7501283212e00efe6a437b24 /markdown
parenta5669823d377ca252a84e28a329c30758995f3da (diff)
downloadmarkdown-834d1a8afe8236d60a994c649e453a650e7594a9.tar.gz
markdown-834d1a8afe8236d60a994c649e453a650e7594a9.tar.bz2
markdown-834d1a8afe8236d60a994c649e453a650e7594a9.zip
Fixed a few bugs in wikilinks url cleaning. And for those who don't like the default, added a config which accepts a callable to replace the default. Updated tests and docs.
Diffstat (limited to 'markdown')
-rw-r--r--markdown/extensions/wikilinks.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/markdown/extensions/wikilinks.py b/markdown/extensions/wikilinks.py
index 147ab62..36a00e8 100644
--- a/markdown/extensions/wikilinks.py
+++ b/markdown/extensions/wikilinks.py
@@ -70,6 +70,13 @@ Dependencies:
'''
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):
@@ -77,7 +84,8 @@ class WikiLinkExtension(markdown.Extension):
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.']
+ 'html_class' : ['wikilink', 'CSS hook. Leave blank for none.'],
+ 'build_url' : [build_url, 'Callable formats URL from label.'],
}
# Override defaults with user settings
@@ -91,8 +99,8 @@ class WikiLinkExtension(markdown.Extension):
WIKILINK_RE = r'\[\[([A-Za-z0-9_ -]+)\]\]'
wikilinkPattern = WikiLinks(WIKILINK_RE, self.config)
wikilinkPattern.md = md
- md.inlinePatterns.add('wikilink', wikilinkPattern, "_end")
-
+ md.inlinePatterns.add('wikilink', wikilinkPattern, "<not_strong")
+
class WikiLinks(markdown.inlinepatterns.Pattern):
def __init__(self, pattern, config):
@@ -103,9 +111,9 @@ class WikiLinks(markdown.inlinepatterns.Pattern):
if m.group(2).strip():
base_url, end_url, html_class = self._getMeta()
label = m.group(2).strip()
- url = '%s%s%s'% (base_url, label.replace(' ', '_'), end_url)
+ url = self.config['build_url'][0](label, base_url, end_url)
a = markdown.etree.Element('a')
- a.text = markdown.AtomicString(label)
+ a.text = label #markdown.AtomicString(label)
a.set('href', url)
if html_class:
a.set('class', html_class)