From 62cc6d185c6f880a12eafca446b64a3707d79c59 Mon Sep 17 00:00:00 2001 From: Mathias Rav Date: Sat, 30 Jun 2018 11:26:41 +0200 Subject: [PATCH] Specify extensions as module names rather than Extension instances --- src/wiki/core/markdown/__init__.py | 9 +++------ src/wiki/core/markdown/mdx/codehilite.py | 5 +++++ src/wiki/core/markdown/mdx/previewlinks.py | 5 +++++ src/wiki/core/markdown/mdx/responsivetable.py | 5 +++++ src/wiki/plugins/macros/mdx/macro.py | 5 +++++ src/wiki/plugins/macros/mdx/toc.py | 5 +++++ src/wiki/plugins/macros/mdx/wikilinks.py | 5 +++++ src/wiki/plugins/macros/wiki_plugin.py | 10 ++++------ 8 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/wiki/core/markdown/__init__.py b/src/wiki/core/markdown/__init__.py index 32c7fca3..a6201382 100644 --- a/src/wiki/core/markdown/__init__.py +++ b/src/wiki/core/markdown/__init__.py @@ -1,9 +1,6 @@ import bleach import markdown from wiki.conf import settings -from wiki.core.markdown.mdx.codehilite import WikiCodeHiliteExtension -from wiki.core.markdown.mdx.previewlinks import PreviewLinksExtension -from wiki.core.markdown.mdx.responsivetable import ResponsiveTableExtension from wiki.core.plugins import registry as plugin_registry @@ -20,9 +17,9 @@ class ArticleMarkdown(markdown.Markdown): def core_extensions(self): """List of core extensions found in the mdx folder""" return [ - PreviewLinksExtension(), - ResponsiveTableExtension(), - WikiCodeHiliteExtension(), + 'wiki.core.markdown.mdx.codehilite', + 'wiki.core.markdown.mdx.previewlinks', + 'wiki.core.markdown.mdx.responsivetable', ] def get_markdown_extensions(self): diff --git a/src/wiki/core/markdown/mdx/codehilite.py b/src/wiki/core/markdown/mdx/codehilite.py index 85c5f81b..b8c2ef6f 100644 --- a/src/wiki/core/markdown/mdx/codehilite.py +++ b/src/wiki/core/markdown/mdx/codehilite.py @@ -117,3 +117,8 @@ class WikiCodeHiliteExtension(CodeHiliteExtension): ">normalize_whitespace") md.registerExtension(self) + + +def makeExtension(*args, **kwargs): + """Return an instance of the extension.""" + return WikiCodeHiliteExtension(*args, **kwargs) diff --git a/src/wiki/core/markdown/mdx/previewlinks.py b/src/wiki/core/markdown/mdx/previewlinks.py index 242bf8d5..f679af3d 100644 --- a/src/wiki/core/markdown/mdx/previewlinks.py +++ b/src/wiki/core/markdown/mdx/previewlinks.py @@ -19,3 +19,8 @@ class PreviewLinksTree(Treeprocessor): if not a.get('href').startswith('#'): a.set('target', '_blank') return root + + +def makeExtension(*args, **kwargs): + """Return an instance of the extension.""" + return PreviewLinksExtension(*args, **kwargs) diff --git a/src/wiki/core/markdown/mdx/responsivetable.py b/src/wiki/core/markdown/mdx/responsivetable.py index 25d68be0..d0e0e03a 100644 --- a/src/wiki/core/markdown/mdx/responsivetable.py +++ b/src/wiki/core/markdown/mdx/responsivetable.py @@ -37,3 +37,8 @@ class ResponsiveTableTree(Treeprocessor): def convert_to_wrapper(self, element): element.tag = 'div' element.set('class', 'table-responsive') + + +def makeExtension(*args, **kwargs): + """Return an instance of the extension.""" + return ResponsiveTableExtension(*args, **kwargs) diff --git a/src/wiki/plugins/macros/mdx/macro.py b/src/wiki/plugins/macros/mdx/macro.py index 4030d4e5..e5adb630 100644 --- a/src/wiki/plugins/macros/mdx/macro.py +++ b/src/wiki/plugins/macros/mdx/macro.py @@ -99,3 +99,8 @@ class MacroPreprocessor(markdown.preprocessors.Preprocessor): 'Insert a link to another wiki page with a short notation.'), example_code='[[WikiLink]]', args={}) + + +def makeExtension(*args, **kwargs): + """Return an instance of the extension.""" + return MacroExtension(*args, **kwargs) diff --git a/src/wiki/plugins/macros/mdx/toc.py b/src/wiki/plugins/macros/mdx/toc.py index b36efdb1..02063260 100644 --- a/src/wiki/plugins/macros/mdx/toc.py +++ b/src/wiki/plugins/macros/mdx/toc.py @@ -309,3 +309,8 @@ class WikiTocExtension(TocExtension): def extendMarkdown(self, md, md_globals): if 'toc' in settings.METHODS: TocExtension.extendMarkdown(self, md, md_globals) + + +def makeExtension(*args, **kwargs): + """Return an instance of the extension.""" + return WikiTocExtension(*args, **kwargs) diff --git a/src/wiki/plugins/macros/mdx/wikilinks.py b/src/wiki/plugins/macros/mdx/wikilinks.py index 4379fe1a..41b6b1c1 100644 --- a/src/wiki/plugins/macros/mdx/wikilinks.py +++ b/src/wiki/plugins/macros/mdx/wikilinks.py @@ -62,3 +62,8 @@ class WikiLinks(wikilinks.WikiLinks): else: a = '' return a + + +def makeExtension(*args, **kwargs): + """Return an instance of the extension.""" + return WikiLinkExtension(*args, **kwargs) diff --git a/src/wiki/plugins/macros/wiki_plugin.py b/src/wiki/plugins/macros/wiki_plugin.py index f34c468c..8e15d217 100644 --- a/src/wiki/plugins/macros/wiki_plugin.py +++ b/src/wiki/plugins/macros/wiki_plugin.py @@ -2,9 +2,6 @@ from django.utils.translation import gettext as _ from wiki.core.plugins import registry from wiki.core.plugins.base import BasePlugin from wiki.plugins.macros import settings -from wiki.plugins.macros.mdx.macro import MacroExtension -from wiki.plugins.macros.mdx.toc import WikiTocExtension -from wiki.plugins.macros.mdx.wikilinks import WikiLinkExtension class MacroPlugin(BasePlugin): @@ -18,9 +15,10 @@ class MacroPlugin(BasePlugin): 'get_form_kwargs': (lambda a: {})} markdown_extensions = [ - WikiLinkExtension(), - MacroExtension(), - WikiTocExtension()] + 'wiki.plugins.macros.mdx.macro', + 'wiki.plugins.macros.mdx.toc', + 'wiki.plugins.macros.mdx.wikilinks', + ] registry.register(MacroPlugin) -- 2.45.2