diff --git a/taiga/mdrender/extensions/wikilinks.py b/taiga/mdrender/extensions/wikilinks.py index a7f2c657..b7f169b5 100644 --- a/taiga/mdrender/extensions/wikilinks.py +++ b/taiga/mdrender/extensions/wikilinks.py @@ -15,69 +15,42 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from __future__ import absolute_import -from __future__ import unicode_literals from markdown import Extension from markdown.inlinepatterns import Pattern from markdown.util import etree -import re - -def build_url(label, base, end): - """ Build a url from the label, a base, and an end. """ - clean_label = re.sub(r'([ ]+_)|(_[ ]+)|([ ]+)', '_', label) - return '%s%s%s' % (base, clean_label, end) +from taiga.front import resolve class WikiLinkExtension(Extension): - def __init__(self, configs): - # set extension defaults - self.config = { - 'base_url': ['/', 'String to append to beginning or URL.'], - 'end_url': ['/', 'String to append to end of URL.'], - 'html_class': ['wikilink', 'CSS hook. Leave blank for none.'], - 'build_url': [build_url, 'Callable formats URL from label.'], - } - configs = dict(configs) or {} - # Override defaults with user settings - for key, value in configs.items(): - self.setConfig(key, value) + def __init__(self, project, *args, **kwargs): + self.project = project + return super().__init__(*args, **kwargs) def extendMarkdown(self, md, md_globals): - self.md = md - - # append to end of inline patterns - WIKILINK_RE = r'\[\[([\w0-9_ -]+)(\|[\w0-9_ -]+)?\]\]' - wikilinkPattern = WikiLinks(WIKILINK_RE, self.getConfigs()) + WIKILINK_RE = r"\[\[([\w0-9_ -]+)(\|[\w0-9_ -]+)?\]\]" + wikilinkPattern = WikiLinksPattern(WIKILINK_RE, self.project) wikilinkPattern.md = md - md.inlinePatterns.add('wikilink', wikilinkPattern, "test

" + expected_result = "

test

" assert render(dummy_project, "[[test]]") == expected_result def test_render_wikilink_with_custom_title(): - expected_result = "

custom

" + expected_result = "

custom

" assert render(dummy_project, "[[test|custom]]") == expected_result