OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from copy import deepcopy | 5 from copy import deepcopy |
6 import logging | 6 import logging |
7 import re | 7 import re |
8 | 8 |
9 from file_system import FileNotFoundError | 9 from file_system import FileNotFoundError |
10 | 10 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 name = name_as_prop_type | 107 name = name_as_prop_type |
108 text = ref.replace(prop['name'], prop['link']['name']) | 108 text = ref.replace(prop['name'], prop['link']['name']) |
109 break | 109 break |
110 if node_info is None: | 110 if node_info is None: |
111 continue | 111 continue |
112 else: | 112 else: |
113 text = ref | 113 text = ref |
114 category, node_name = node_info | 114 category, node_name = node_info |
115 if namespace is not None and text.startswith('%s.' % namespace): | 115 if namespace is not None and text.startswith('%s.' % namespace): |
116 text = text[len('%s.' % namespace):] | 116 text = text[len('%s.' % namespace):] |
| 117 api_model = self._api_models.GetModel(api_name).Get() |
| 118 filename = api_model.documentation_options.get('documented_in', api_name) |
117 return { | 119 return { |
118 'href': '%s.html#%s-%s' % (api_name, category, name.replace('.', '-')), | 120 'href': '%s#%s-%s' % (filename, category, name.replace('.', '-')), |
119 'text': text, | 121 'text': text, |
120 'name': node_name | 122 'name': node_name |
121 } | 123 } |
122 | 124 |
123 # If it's not a reference to an API node it might just be a reference to an | 125 # If it's not a reference to an API node it might just be a reference to an |
124 # API. Check this last so that links within APIs take precedence over links | 126 # API. Check this last so that links within APIs take precedence over links |
125 # to other APIs. | 127 # to other APIs. |
126 if ref in api_list: | 128 if ref in api_list: |
127 return { | 129 return { |
128 'href': '%s.html' % ref, | 130 'href': '%s' % ref, |
129 'text': ref, | 131 'text': ref, |
130 'name': ref | 132 'name': ref |
131 } | 133 } |
132 | 134 |
133 return None | 135 return None |
134 | 136 |
135 def GetLink(self, ref, namespace=None, title=None): | 137 def GetLink(self, ref, namespace=None, title=None): |
136 """Resolve $ref |ref| in namespace |namespace| if not None, returning None | 138 """Resolve $ref |ref| in namespace |namespace| if not None, returning None |
137 if it cannot be resolved. | 139 if it cannot be resolved. |
138 """ | 140 """ |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 ref = '' | 210 ref = '' |
209 rest = ref_and_rest | 211 rest = ref_and_rest |
210 else: | 212 else: |
211 ref = match.group() | 213 ref = match.group() |
212 rest = ref_and_rest[match.end():] | 214 rest = ref_and_rest[match.end():] |
213 | 215 |
214 ref_dict = self.SafeGetLink(ref, namespace=namespace, title=title) | 216 ref_dict = self.SafeGetLink(ref, namespace=namespace, title=title) |
215 formatted_text.append('<a href="%s%s">%s</a>%s' % | 217 formatted_text.append('<a href="%s%s">%s</a>%s' % |
216 (link_prefix, ref_dict['href'], ref_dict['text'], rest)) | 218 (link_prefix, ref_dict['href'], ref_dict['text'], rest)) |
217 return ''.join(formatted_text) | 219 return ''.join(formatted_text) |
OLD | NEW |