Replace "@{symbol}" references with links to symbol's documentation page. This functions finds all occurrences of "@{symbol}" in `string` and replaces them with markdown links to the documentation page for "symbol". `relative_path_to_root` is the relative path from the document
(self, string, relative_path_to_root)
| 258 | json.dump(json_dict, f, indent=2, sort_keys=True) |
| 259 | |
| 260 | def replace_references(self, string, relative_path_to_root): |
| 261 | """Replace "@{symbol}" references with links to symbol's documentation page. |
| 262 | |
| 263 | This functions finds all occurrences of "@{symbol}" in `string` |
| 264 | and replaces them with markdown links to the documentation page |
| 265 | for "symbol". |
| 266 | |
| 267 | `relative_path_to_root` is the relative path from the document |
| 268 | that contains the "@{symbol}" reference to the root of the API |
| 269 | documentation that is linked to. If the containing page is part of |
| 270 | the same API docset, `relative_path_to_root` can be set to |
| 271 | `os.path.dirname(documentation_path(name))`, where `name` is the |
| 272 | python name of the object whose documentation page the reference |
| 273 | lives on. |
| 274 | |
| 275 | Args: |
| 276 | string: A string in which "@{symbol}" references should be replaced. |
| 277 | relative_path_to_root: The relative path from the containing document to |
| 278 | the root of the API documentation that is being linked to. |
| 279 | |
| 280 | Returns: |
| 281 | `string`, with "@{symbol}" references replaced by Markdown links. |
| 282 | """ |
| 283 | |
| 284 | def strict_one_ref(match): |
| 285 | try: |
| 286 | return self._one_ref(match, relative_path_to_root) |
| 287 | except TFDocsError as e: |
| 288 | self.add_error(e.message) |
| 289 | return 'BAD_LINK' |
| 290 | |
| 291 | string = re.sub(SYMBOL_REFERENCE_RE, strict_one_ref, string) |
| 292 | |
| 293 | def sloppy_one_ref(match): |
| 294 | try: |
| 295 | return self._one_ref(match, relative_path_to_root) |
| 296 | except TFDocsError: |
| 297 | return match.group(0) |
| 298 | |
| 299 | string = re.sub(AUTO_REFERENCE_RE, sloppy_one_ref, string) |
| 300 | |
| 301 | return string |
| 302 | |
| 303 | def python_link(self, link_text, ref_full_name, relative_path_to_root, |
| 304 | code_ref=True): |