Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: cms/converters.py

Issue 30044555: Issue 7461 - Include source page into warning text for unresolved links (Closed) Base URL: https://hg.adblockplus.org/cms
Patch Set: Improve readability of the error message Created April 15, 2019, 4:48 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | cms/sources.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cms/converters.py
===================================================================
--- a/cms/converters.py
+++ b/cms/converters.py
@@ -304,19 +304,19 @@
# Links to an external resource
return target
return relpath(target, base_url.rsplit('/', 1)[0])
def process_link(match):
pre, attr, url, post = match.groups()
url = jinja2.Markup(url).unescape()
- locale, new_url = (
- self._params['source']
- .resolve_link(url, self._params['locale']))
+ locale, new_url = self._params['source'].resolve_link(
+ url, self._params['locale'], self._params['page'],
+ )
if new_url is not None:
url = new_url
if attr == 'href':
post += ' hreflang="{}"'\
.format(jinja2.Markup.escape(locale))
if self._params['relative']:
@@ -511,17 +511,18 @@
if locale is None:
locale = self._params['locale']
return utils.get_page_params(self._params['source'], locale, page)
def linkify(self, page, locale=None, **attrs):
if locale is None:
locale = self._params['locale']
- locale, url = self._params['source'].resolve_link(page, locale)
+ locale, url = self._params['source'].resolve_link(page, locale,
+ self._params['page'])
return jinja2.Markup('<a{}>'.format(''.join(
' {}="{}"'.format(name, jinja2.escape(value)) for name, value in [
('href', url),
('hreflang', locale),
] + attrs.items()
)))
def get_pages_metadata(self, filters=None):
@@ -558,17 +559,17 @@
"""Return canonical URL for the page (without locale code)"""
try:
base_url = self._params['site_url']
except KeyError:
raise Exception('You must configure `siteurl` to use'
'`get_canonical_url()`')
locale, page_url = self._params['source'].resolve_link(
- page, self._params['locale'],
+ page, self._params['locale'], self._params['page'],
)
# Remove the locale component that `resolve_link` adds at the
# beginning.
page_url = page_url[len(locale) + 1:]
return urlparse.urljoin(base_url, page_url)
def toclist(self, content):
toc_re = r'<h(\d)\s[^<>]*\bid="([^<>"]+)"[^<>]*>(.*?)</h\1>'
@@ -592,17 +593,18 @@
def page_has_locale(self, page, locale):
return self._params['source'].has_locale(locale, page)
def get_page_url(self, page, locale=None, redirect=False):
if not locale:
locale = self._params['locale']
if self.page_has_locale(page, locale) or redirect:
- return self._params['source'].resolve_link(page, locale)[1]
+ return self._params['source'].resolve_link(page, locale,
+ self._params['page'])[1]
raise Exception('{} does not exist in {}'.format(page, locale))
converters = {
'html': RawConverter,
'md': MarkdownConverter,
'tmpl': TemplateConverter,
}
« no previous file with comments | « no previous file | cms/sources.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld