Commit 012e5181 by Bridger Maxwell

Fixed wikipath extension

parent ea392495
...@@ -16,7 +16,6 @@ class WikiPathExtension(markdown.Extension): ...@@ -16,7 +16,6 @@ class WikiPathExtension(markdown.Extension):
# set extension defaults # set extension defaults
self.config = { self.config = {
'base_url' : ['/', 'String to append to beginning or URL.'], 'base_url' : ['/', 'String to append to beginning or URL.'],
'end_url' : ['/', 'String to append to end of URL.'],
'html_class' : ['wikipath', 'CSS hook. Leave blank for none.'] 'html_class' : ['wikipath', 'CSS hook. Leave blank for none.']
} }
...@@ -31,7 +30,7 @@ class WikiPathExtension(markdown.Extension): ...@@ -31,7 +30,7 @@ class WikiPathExtension(markdown.Extension):
# append to end of inline patterns # append to end of inline patterns
WIKI_RE = r'\[(?P<linkTitle>.+?)\]\(wiki:(?P<wikiTitle>[a-zA-Z\d/_-]*)\)' WIKI_RE = r'\[(?P<linkTitle>.+?)\]\(wiki:(?P<wikiTitle>[a-zA-Z\d/_-]*)\)'
wikiPathPattern = WikiPath(WIKI_RE, self.getConfigs()) wikiPathPattern = WikiPath(WIKI_RE, self.config)
wikiPathPattern.md = md wikiPathPattern.md = md
md.inlinePatterns.add('wikipath', wikiPathPattern, "<reference") md.inlinePatterns.add('wikipath', wikiPathPattern, "<reference")
...@@ -45,30 +44,27 @@ class WikiPath(markdown.inlinepatterns.Pattern): ...@@ -45,30 +44,27 @@ class WikiPath(markdown.inlinepatterns.Pattern):
if article_title.startswith("/"): if article_title.startswith("/"):
article_title = article_title[1:] article_title = article_title[1:]
url = self.config['base_url'] + article_title url = self.config['base_url'][0] + article_title
label = m.group('linkTitle') label = m.group('linkTitle')
a = etree.Element('a') a = etree.Element('a')
a.set('href', url) a.set('href', url)
a.text = label a.text = label
if self.config['html_class']: if self.config['html_class'][0]:
a.set('class', self.config['html_class']) a.set('class', self.config['html_class'][0])
return a return a
def _getMeta(self): def _getMeta(self):
""" Return meta data or config data. """ """ Return meta data or config data. """
base_url = self.config['base_url'] base_url = self.config['base_url'][0]
end_url = self.config['end_url'] html_class = self.config['html_class'][0]
html_class = self.config['html_class']
if hasattr(self.md, 'Meta'): if hasattr(self.md, 'Meta'):
if self.md.Meta.has_key('wiki_base_url'): if self.md.Meta.has_key('wiki_base_url'):
base_url = self.md.Meta['wiki_base_url'][0] 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'): if self.md.Meta.has_key('wiki_html_class'):
html_class = self.md.Meta['wiki_html_class'][0] html_class = self.md.Meta['wiki_html_class'][0]
return base_url, end_url, html_class return base_url, html_class
def makeExtension(configs=None) : def makeExtension(configs=None) :
return WikiPathExtension(configs=configs) return WikiPathExtension(configs=configs)
......
...@@ -267,7 +267,7 @@ class Revision(models.Model): ...@@ -267,7 +267,7 @@ class Revision(models.Model):
# Create pre-parsed contents - no need to parse on-the-fly # Create pre-parsed contents - no need to parse on-the-fly
ext = WIKI_MARKDOWN_EXTENSIONS ext = WIKI_MARKDOWN_EXTENSIONS
#ext += ["wikipath(base_url=%s)" % reverse('wiki_view', args=('/',))] ext += ["wikipath(base_url=%s)" % reverse('wiki_view', args=('/',))]
print ext print ext
self.contents_parsed = markdown(self.contents, self.contents_parsed = markdown(self.contents,
extensions=ext, extensions=ext,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment