From: Michael Tremer Date: Thu, 6 Dec 2018 15:14:03 +0000 (+0000) Subject: wiki: Add support for relative links X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=78738820829a632dafd59891f4428160b91c37de;p=ipfire.org.git wiki: Add support for relative links Signed-off-by: Michael Tremer --- diff --git a/src/backend/wiki.py b/src/backend/wiki.py index ab98b9a3..72383672 100644 --- a/src/backend/wiki.py +++ b/src/backend/wiki.py @@ -305,19 +305,26 @@ class Page(misc.Object): # Add wiki links patterns = ( - (r"\[\[([\w\d\/]+)(?:\|([\w\d\s]+))\]\]", r"/\1", r"\2", None, None), - (r"\[\[([\w\d\/\-]+)\]\]", r"/\1", r"\1", self.backend.wiki.get_page_title, r"\1"), + (r"\[\[([\w\d\/]+)(?:\|([\w\d\s]+))\]\]", r"/\1", r"\2", None), + (r"\[\[([\w\d\/\-\.]+)\]\]", r"\1", r"\1", self.backend.wiki.get_page_title), ) - for pattern, link, title, repl, args in patterns: + for pattern, link, title, repl in patterns: replacements = [] for match in re.finditer(pattern, text): l = match.expand(link) t = match.expand(title) + # Allow relative links + if not l.startswith("/"): + l = os.path.join(self.page, l) + + # Normalise links + l = os.path.normpath(l) + if callable(repl): - t = repl(match.expand(args)) or t + t = repl(l) or t replacements.append((match.span(), t or l, l))