| 84 | |
| 85 | def on_page_markdown(markdown: str, page, config, *args, **kwargs): |
| 86 | def replace_cli_link(match): |
| 87 | global api_links |
| 88 | link_text = match.group(1) |
| 89 | pyapi_key = match.group(2) |
| 90 | hash = match.group(3) or "" |
| 91 | link_url = url_map.get(pyapi_key) |
| 92 | if link_url: |
| 93 | api_links += 1 |
| 94 | pyapi_url = f"{site_url}{link_url}" |
| 95 | return f"[{link_text}]({pyapi_url}{hash})" |
| 96 | else: |
| 97 | raise Exception(f"PyAPI link key {pyapi_key} not found in {page.file.src_path}") |
| 98 | |
| 99 | return PYAPI_LINK_REGEX.sub(replace_cli_link, markdown) |
| 100 | |