Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2569)

Unified Diff: chrome/common/extensions/docs/server2/reference_resolver.py

Issue 80183002: Correct $ref links in extensions documentation server relative location. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/reference_resolver.py
diff --git a/chrome/common/extensions/docs/server2/reference_resolver.py b/chrome/common/extensions/docs/server2/reference_resolver.py
index 4a344fbf9aed4f0253bcc8a99e9833b7221beb05..126858114d91afb0e237665cd3bf54f77db57212 100644
--- a/chrome/common/extensions/docs/server2/reference_resolver.py
+++ b/chrome/common/extensions/docs/server2/reference_resolver.py
@@ -44,6 +44,17 @@ def _MakeKey(namespace, ref):
key = key[:max_size]
return key
+def _DetermineLinkPrefix(request):
+ # request.Path should be of the form (apps|extensions)/...../page.html. This
+ # function works out the relative path prefix required so that the target
+ # will point to (apps|extensions)/target.html. This is as many '../' as there
+ # are components between (apps|extensiosn) and page.html, in the example
+ # above
+ prefix = ''
+ components = request.path.split('/')[2:]
+ for piece in components:
+ prefix = prefix + '../'
+ return prefix
not at google - send to devlin 2013/11/21 05:26:50 could be written as '../' * (path.count('/') - 1)
benwells 2013/11/22 05:44:01 holy cow, I can multiple strings with numbers !?!?
class ReferenceResolver(object):
"""Resolves references to $ref's by searching through the APIs to find the
@@ -170,13 +181,18 @@ class ReferenceResolver(object):
'name': ref
}
- def ResolveAllLinks(self, text, namespace=None):
+ def ResolveAllLinks(self, text, request, namespace=None):
not at google - send to devlin 2013/11/21 05:26:50 Rather than introduce a whole Request as a (concep
benwells 2013/11/22 05:44:01 Done.
"""This method will resolve all $ref links in |text| using namespace
|namespace| if not None. Any links that cannot be resolved will be replaced
using the default link format that |SafeGetLink| uses.
+ The links are relative, with the prefix for the path determined by
+ inspecting request.path.
"""
if text is None or '$ref:' not in text:
return text
+ link_prefix = ''
+ if request is not None:
+ link_prefix = _DetermineLinkPrefix(request)
split_text = text.split('$ref:')
# |split_text| is an array of text chunks that all start with the
# argument to '$ref:'.
@@ -204,6 +220,9 @@ class ReferenceResolver(object):
rest = ref_and_rest[match.end():]
ref_dict = self.SafeGetLink(ref, namespace=namespace, title=title)
- formatted_text.append('<a href="%(href)s">%(text)s</a>%(rest)s' %
- { 'href': ref_dict['href'], 'text': ref_dict['text'], 'rest': rest })
+ formatted_text.append('<a href="%(prefix)s%(href)s">%(text)s</a>%(rest)s' %
+ { 'prefix': link_prefix,
+ 'href': ref_dict['href'],
+ 'text': ref_dict['text'],
+ 'rest': rest })
not at google - send to devlin 2013/11/21 05:26:50 we should kill this confusing %(prefix)s stuff and
benwells 2013/11/22 05:44:01 Done.
return ''.join(formatted_text)

Powered by Google App Engine
This is Rietveld 408576698