~netlandish/django-wiki

90be0603da56ffbb79c10ad7f378891e19e98daf — Mathias Rav 6 years ago c9b7f0b
Wikilinks: Use new config API

Accept **kwargs in __init__() instead of a `configs` sequence.

Also inherit from Extension directly since nothing in Markdown's
WikilinksExtension is used (and to avoid Markdown's extension overriding
the config in django-wiki's extension).
1 files changed, 4 insertions(+), 7 deletions(-)

M src/wiki/plugins/macros/mdx/wikilinks.py
M src/wiki/plugins/macros/mdx/wikilinks.py => src/wiki/plugins/macros/mdx/wikilinks.py +4 -7
@@ 5,7 5,7 @@ import re

import markdown
from django.urls import reverse
from markdown.extensions import wikilinks
from markdown.extensions import Extension, wikilinks


def build_url(label, base, end, md):


@@ 22,9 22,9 @@ def build_url(label, base, end, md):
    return '%s%s%s' % (base, clean_label, end)


class WikiLinkExtension(wikilinks.WikiLinkExtension):
class WikiLinkExtension(Extension):

    def __init__(self, configs={}):
    def __init__(self, **kwargs):
        # set extension defaults
        self.config = {
            'base_url': ['', 'String to append to beginning or URL.'],


@@ 32,10 32,7 @@ class WikiLinkExtension(wikilinks.WikiLinkExtension):
            'html_class': ['wiki_wikilink', 'CSS hook. Leave blank for none.'],
            'build_url': [build_url, 'Callable formats URL from label.'],
        }

        # Override defaults with user settings
        for key, value in configs:
            self.setConfig(key, value)
        super().__init__(**kwargs)

    def extendMarkdown(self, md, md_globals):
        self.md = md