Skip to content

Commit

Permalink
Merge pull request #32 from edx/jmbowman/PLAT-1945
Browse files Browse the repository at this point in the history
PLAT-1945 Fix deprecated Markdown extension initialization
  • Loading branch information
Jeremy Bowman committed Feb 7, 2018
2 parents b108ad3 + 913c386 commit 9806353
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def build_media_pattern(base_folder, file_extension):

setup(
name = "django-wiki",
version="0.0.16",
version="0.0.17",
author = "Benjamin Bach",
author_email = "[email protected]",
description = ("A wiki system written for the Django framework."),
Expand Down
22 changes: 12 additions & 10 deletions wiki/plugins/links/mdx/djangowikilinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,19 @@
except ImportError:
from markdown import etree #@UnresolvedImport @Reimport


class WikiPathExtension(markdown.Extension):
def __init__(self, configs):
def __init__(self, **kwargs):
# 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.']
'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)
super(WikiPathExtension, self).__init__(**kwargs)

def extendMarkdown(self, md, md_globals):
self.md = md
Expand All @@ -54,6 +53,7 @@ def extendMarkdown(self, md, md_globals):
wikiPathPattern.md = md
md.inlinePatterns.add('djangowikipath', wikiPathPattern, "<reference")


class WikiPath(markdown.inlinepatterns.Pattern):
def __init__(self, pattern, config, **kwargs):
markdown.inlinepatterns.Pattern.__init__(self, pattern, **kwargs)
Expand Down Expand Up @@ -130,8 +130,10 @@ def _getMeta(self):
html_class = self.md.Meta['wiki_html_class'][0]
return base_url, html_class

def makeExtension(configs=None) :
return WikiPathExtension(configs=configs)

def makeExtension(**kwargs):
return WikiPathExtension(**kwargs)


if __name__ == "__main__":
import doctest
Expand Down
12 changes: 7 additions & 5 deletions wiki/plugins/links/mdx/urlize.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
r'(?:/?|[/?]\S+))'
)


class UrlizePattern(markdown.inlinepatterns.Pattern):

def __init__(self, pattern, markdown_instance=None):
Expand Down Expand Up @@ -87,18 +88,19 @@ def handleMatch(self, m):
el.extend([icon, span_text])
return el


class UrlizeExtension(markdown.Extension):
""" Urlize Extension for Python-Markdown. """

def extendMarkdown(self, md, md_globals):
""" Replace autolink with UrlizePattern """
md.inlinePatterns['autolink'] = UrlizePattern(URLIZE_RE, md)

def makeExtension(configs=None):
if configs is None:
configs = {}
return UrlizeExtension(configs=configs)

def makeExtension(**kwargs):
return UrlizeExtension(**kwargs)


if __name__ == "__main__":
import doctest
doctest.testmod()
doctest.testmod()
7 changes: 4 additions & 3 deletions wiki/plugins/links/wiki_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from wiki.plugins.links.mdx.djangowikilinks import WikiPathExtension
from django.core.urlresolvers import reverse_lazy


class LinkPlugin(BasePlugin):

slug = 'links'
Expand All @@ -29,10 +30,10 @@ class LinkPlugin(BasePlugin):
('default_level', settings.LINK_DEFAULT_LEVEL ),
]

markdown_extensions = [makeExtension(), WikiPathExtension(wikipath_config)]
markdown_extensions = [makeExtension(), WikiPathExtension(**dict(wikipath_config))]

def __init__(self):
pass

registry.register(LinkPlugin)


registry.register(LinkPlugin)

0 comments on commit 9806353

Please sign in to comment.