Commit 67fe4d99 by David Baumgold

Use Markdown 2.5

parent cd0b2b31
......@@ -119,7 +119,7 @@ So far the dependencies are:
* [django=>1.4](http://www.djangoproject.com)
* [django-south](http://south.aeracode.org/)
* [Markdown>=2.2.0](https://github.com/waylan/Python-Markdown)
* [Markdown>=2.5.0](https://github.com/waylan/Python-Markdown)
* [django-mptt>=0.5](https://github.com/django-mptt/django-mptt)
* [django-sekizai](https://github.com/ojii/django-sekizai/)
* [sorl-thumbnail](https://github.com/sorl/sorl-thumbnail)
......
......@@ -31,23 +31,16 @@ except ImportError:
from markdown import etree #@UnresolvedImport @Reimport
class WikiPathExtension(markdown.Extension):
def __init__(self, configs):
# set extension defaults
self.config = {
'base_url' : ['/', 'String to append to beginning of URL.'],
'html_class' : ['wikipath', 'CSS hook. Leave blank for none.'],
'live_lookups' : [True, 'If the plugin should try and match links to real articles'],
'default_level' : [2, 'The level that most articles are created at. Relative links will tend to start at that level.']
}
# Override defaults with user settings
for key, value in configs :
# self.config[key][0] = value
self.setConfig(key, value)
config = {
'base_url': ['/', 'String to append to beginning of URL.'],
'html_class': ['wikipath', 'CSS hook. Leave blank for none.'],
'live_lookups': [True, 'If the plugin should try and match links to real articles'],
'default_level': [2, 'The level that most articles are created at. Relative links will tend to start at that level.'],
}
def extendMarkdown(self, md, md_globals):
self.md = md
# append to end of inline patterns
WIKI_RE = r'\[(?P<linkTitle>[^\]]+?)\]\(wiki:(?P<wikiTitle>[a-zA-Z\d\./_-]*)\)'
wikiPathPattern = WikiPath(WIKI_RE, self.config, markdown_instance=md)
......@@ -58,7 +51,7 @@ class WikiPath(markdown.inlinepatterns.Pattern):
def __init__(self, pattern, config, **kwargs):
markdown.inlinepatterns.Pattern.__init__(self, pattern, **kwargs)
self.config = config
def handleMatch(self, m) :
from wiki import models
article_title = m.group('wikiTitle')
......@@ -66,7 +59,7 @@ class WikiPath(markdown.inlinepatterns.Pattern):
if article_title.startswith("/"):
absolute = True
article_title = article_title.strip("/")
# Use this to calculate some kind of meaningful path
# from the link, regardless of whether or not something can be
# looked up
......@@ -75,7 +68,7 @@ class WikiPath(markdown.inlinepatterns.Pattern):
if absolute:
base_path = self.config['base_url'][0]
path_from_link = os_path.join(base_path, article_title)
urlpath = None
path = path_from_link
if self.config['live_lookups'][0]:
......@@ -91,23 +84,23 @@ class WikiPath(markdown.inlinepatterns.Pattern):
# one more component would make a path of length self.config['default_level']
starting_level = max(0, self.config['default_level'][0] - 1 )
starting_path = "/".join(source_components[ : starting_level ])
path_from_link = os_path.join(starting_path, article_title)
lookup = models.URLPath.objects.none()
if self.config['live_lookups'][0]:
if urlpath.parent:
lookup = urlpath.parent.get_descendants().filter(slug=article_title)
else:
lookup = urlpath.get_descendants().filter(slug=article_title)
if lookup.count() > 0:
urlpath = lookup[0]
path = urlpath.get_absolute_url()
else:
urlpath = None
path = self.config['base_url'][0] + path_from_link
label = m.group('linkTitle')
a = etree.Element('a')
a.set('href', path)
......@@ -116,9 +109,9 @@ class WikiPath(markdown.inlinepatterns.Pattern):
else:
a.set('class', self.config['html_class'][0])
a.text = label
return a
def _getMeta(self):
""" Return meta data or config data. """
base_url = self.config['base_url'][0]
......@@ -130,9 +123,6 @@ class WikiPath(markdown.inlinepatterns.Pattern):
html_class = self.md.Meta['wiki_html_class'][0]
return base_url, html_class
def makeExtension(configs=None) :
return WikiPathExtension(configs=configs)
if __name__ == "__main__":
import doctest
doctest.testmod()
......@@ -58,7 +58,7 @@ class UrlizePattern(markdown.inlinepatterns.Pattern):
def __init__(self, pattern, markdown_instance=None):
markdown.inlinepatterns.Pattern.__init__(self, pattern, markdown_instance=markdown_instance)
self.compiled_re = re.compile("^(.*?)%s(.*?)$" % pattern,
self.compiled_re = re.compile("^(.*?)%s(.*?)$" % pattern,
re.DOTALL | re.UNICODE | re.IGNORECASE)
""" Return a link Element given an autolink (`http://example/com`). """
......@@ -67,18 +67,18 @@ class UrlizePattern(markdown.inlinepatterns.Pattern):
if url.startswith('<'):
url = url[1:-1]
text = url
if not url.split('://')[0] in ('http','https','ftp'):
if '@' in url and not '/' in url:
url = 'mailto:' + url
else:
url = 'http://' + url
icon = markdown.util.etree.Element("span")
icon.set('class', 'icon-globe')
span_text = markdown.util.etree.Element("span")
span_text.text = markdown.util.AtomicString(" " + text)
el = markdown.util.etree.Element("a")
......@@ -94,9 +94,6 @@ class UrlizeExtension(markdown.Extension):
""" Replace autolink with UrlizePattern """
md.inlinePatterns['autolink'] = UrlizePattern(URLIZE_RE, md)
def makeExtension(configs=None):
return UrlizeExtension(configs=configs)
if __name__ == "__main__":
import doctest
doctest.testmod()
\ No newline at end of file
doctest.testmod()
......@@ -6,33 +6,33 @@ from wiki.conf import settings
from wiki.core.plugins import registry
from wiki.core.plugins.base import BasePlugin
from wiki.plugins.links import views
from wiki.plugins.links.mdx.urlize import makeExtension
from wiki.plugins.links.mdx.urlize import UrlizeExtension
from wiki.plugins.links.mdx.djangowikilinks import WikiPathExtension
from django.core.urlresolvers import reverse_lazy
class LinkPlugin(BasePlugin):
slug = 'links'
urlpatterns = patterns('',
url(r'^json/query-urlpath/$', views.QueryUrlPath.as_view(), name='links_query_urlpath'),
)
sidebar = {'headline': _('Links'),
'icon_class': 'icon-bookmark',
'template': 'wiki/plugins/links/sidebar.html',
'form_class': None,
'get_form_kwargs': (lambda a: {})}
wikipath_config = [
('base_url', reverse_lazy('wiki:get', kwargs={'path': ''}) ),
('live_lookups', settings.LINK_LIVE_LOOKUPS ),
('default_level', settings.LINK_DEFAULT_LEVEL ),
]
markdown_extensions = [makeExtension(), WikiPathExtension(wikipath_config)]
wikipath_ext = WikiPathExtension(
base_url=reverse_lazy('wiki:get', kwargs={'path': ''}),
live_lookups=settings.LINK_LIVE_LOOKUPS,
default_level=settings.LINK_DEFAULT_LEVEL,
)
markdown_extensions = [UrlizeExtension(), wikipath_ext]
def __init__(self):
pass
registry.register(LinkPlugin)
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