Index: cms/converters.py |
=================================================================== |
--- a/cms/converters.py |
+++ b/cms/converters.py |
@@ -19,6 +19,7 @@ |
import HTMLParser |
import re |
import urlparse |
+from posixpath import relpath |
import jinja2 |
import markdown |
@@ -298,6 +299,15 @@ |
) |
def process_links(self, text): |
+ def make_relative(base_url, target): |
+ if not target.startswith('/'): |
+ # Links to an external resource |
+ return target |
+ if base_url == target: |
Vasily Kuznetsov
2018/11/06 12:45:17
This special case should not be necessary if the a
rhowell
2018/11/07 16:16:58
Done.
|
+ target = target.split('/') |
+ return target[-1] |
+ return relpath(target, base_url) |
+ |
def process_link(match): |
pre, attr, url, post = match.groups() |
url = jinja2.Markup(url).unescape() |
@@ -312,6 +322,10 @@ |
post += ' hreflang="{}"'\ |
.format(jinja2.Markup.escape(locale)) |
+ if self._params['relative']: |
+ current_path = '/' + self._params['locale'] |
+ url = make_relative(current_path, url) |
+ |
return ''.join((pre, jinja2.Markup.escape(url), post)) |
text = re.sub(r'(<a\s[^<>]*\b(href)=\")([^<>\"]+)(\")', |
@@ -432,6 +446,7 @@ |
'get_page_content': self.get_page_content, |
'get_pages_metadata': self.get_pages_metadata, |
'get_canonical_url': self.get_canonical_url, |
+ 'relative': self._params['relative'], |
} |
for dirname, dictionary in [('filters', filters), |