Commit 4a664d88 by Bridger Maxwell

Added new wiki link format. [Some Article](wiki:SomeArticle)

parent ad027253
...@@ -210,7 +210,7 @@ LOGGING = { ...@@ -210,7 +210,7 @@ LOGGING = {
'level' : 'INFO' 'level' : 'INFO'
}, },
'tracking' : { 'tracking' : {
'handlers' : handlers, 'handlers' : [], # handlers,
'level' : 'DEBUG', 'level' : 'DEBUG',
'propagate' : False, 'propagate' : False,
}, },
......
...@@ -75,68 +75,67 @@ except: ...@@ -75,68 +75,67 @@ except:
from markdown import etree from markdown import etree
class CamelCaseExtension(markdown.Extension): class WikiPathExtension(markdown.Extension):
def __init__(self, configs): def __init__(self, configs):
# 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.'], 'end_url' : ['/', 'String to append to end of URL.'],
'html_class' : ['wikilink', 'CSS hook. Leave blank for none.'] 'html_class' : ['wikipath', 'CSS hook. Leave blank for none.']
} }
# Override defaults with user settings # Override defaults with user settings
for key, value in configs : for key, value in configs :
# self.config[key][0] = value # self.config[key][0] = value
self.setConfig(key, value) self.setConfig(key, value)
def add_inline(self, md, name, klass, re):
pattern = klass(re)
pattern.md = md
pattern.ext = self
md.inlinePatterns.add(name, pattern, "<reference")
def extendMarkdown(self, md, md_globals): def extendMarkdown(self, md, md_globals):
self.add_inline(md, 'camel', CamelCaseLinks, self.md = md
r'''(?P<escape>\\|\b)(?P<camelcase>([A-Z]+[a-z-_]+){2,})(?:"")?\b''')
# append to end of inline patterns
class CamelCaseLinks(markdown.inlinepatterns.Pattern): WIKI_RE = r'\[(?P<linkTitle>.+?)\]\(wiki:(?P<wikiTitle>[a-zA-Z\d/_-]*)\)'
wikiPathPattern = WikiPath(WIKI_RE, self.getConfigs())
wikiPathPattern.md = md
md.inlinePatterns.add('wikipath', wikiPathPattern, "<reference")
class WikiPath(markdown.inlinepatterns.Pattern):
def __init__(self, pattern, config):
markdown.inlinepatterns.Pattern.__init__(self, pattern)
self.config = config
def handleMatch(self, m) : def handleMatch(self, m) :
if m.group('escape') == '\\': article_title = m.group('wikiTitle')
a = etree.Element('a')#doc.createTextNode(m.group('camelcase')) if article_title.startswith("/"):
else : article_title = article_title[1:]
url = m.group('camelcase') + "/"
#'%s%s%s'% (self.md.wiki_config['base_url'][0], \ url = self.config['base_url'] + article_title
#m.group('camelcase'), \ label = m.group('linkTitle')
#self.md.wiki_config['end_url'][0]) a = etree.Element('a')
label = m.group('camelcase').replace('_', ' ') a.set('href', url)
a = etree.Element('a') a.text = label
a.set('href', url)
a.text = label if self.config['html_class']:
a.set('class', 'wikilink') a.set('class', self.config['html_class'])
return a return a
class CamelCasePreprocessor(markdown.preprocessors.Preprocessor) :
def run(self, lines) :
'''
Updates WikiLink Extension configs with Meta Data.
Passes "lines" through unchanged.
Run as a preprocessor because must run after the def _getMeta(self):
MetaPreprocessor runs and only needs to run once. """ Return meta data or config data. """
''' base_url = self.config['base_url']
end_url = self.config['end_url']
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'):
self.md.wiki_config['base_url'][0] = 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'): if self.md.Meta.has_key('wiki_end_url'):
self.md.wiki_config['end_url'][0] = self.md.Meta['wiki_end_url'][0] 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'):
self.md.wiki_config['html_class'][0] = self.md.Meta['wiki_html_class'][0] html_class = self.md.Meta['wiki_html_class'][0]
return base_url, end_url, html_class
return lines
def makeExtension(configs=None) : def makeExtension(configs=None) :
return CamelCaseExtension(configs=configs) return WikiPathExtension(configs=configs)
if __name__ == "__main__": if __name__ == "__main__":
import doctest import doctest
......
...@@ -267,8 +267,8 @@ class Revision(models.Model): ...@@ -267,8 +267,8 @@ 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
# TODO: Replace with a real wikilinks module ext += ["wikipath(base_url=%s)" % reverse('wiki_view', args=('/',))]
# ext += ["wikilinks(base_url=%s/)" % reverse('wiki_view', args=('',))] print ext
self.contents_parsed = markdown(self.contents, self.contents_parsed = markdown(self.contents,
extensions=ext, extensions=ext,
safe_mode='escape',) safe_mode='escape',)
......
...@@ -75,7 +75,7 @@ WIKI_CONTEXT_PREPROCESSORS = getattr(settings, 'SIMPLE_WIKI_CONTEXT_PREPROCESSOR ...@@ -75,7 +75,7 @@ WIKI_CONTEXT_PREPROCESSORS = getattr(settings, 'SIMPLE_WIKI_CONTEXT_PREPROCESSOR
# List of extensions to be used by Markdown. Custom extensions (i.e., with file # List of extensions to be used by Markdown. Custom extensions (i.e., with file
# names of mdx_*.py) can be dropped into the simplewiki (or project) directory # names of mdx_*.py) can be dropped into the simplewiki (or project) directory
# and then added to this list to be utilized. Wikilinks is always enabled. # and then added to this list to be utilized. Wiki is enabled automatically.
# #
# For more information, see # For more information, see
# http://www.freewisdom.org/projects/python-markdown/Available_Extensions # http://www.freewisdom.org/projects/python-markdown/Available_Extensions
...@@ -90,7 +90,7 @@ WIKI_MARKDOWN_EXTENSIONS = getattr(settings, 'SIMPLE_WIKI_MARKDOWN_EXTENSIONS', ...@@ -90,7 +90,7 @@ WIKI_MARKDOWN_EXTENSIONS = getattr(settings, 'SIMPLE_WIKI_MARKDOWN_EXTENSIONS',
'toc', 'toc',
'mathjax', 'mathjax',
'video', # In-line embedding for YouTube, etc. 'video', # In-line embedding for YouTube, etc.
'circuit' 'circuit',
]) ])
......
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