| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import typing as t |
| 4 |
|
| 5 |
from docutils import nodes |
| 6 |
|
| 7 |
from .utils import derive_doc_url_base |
| 8 |
|
| 9 |
|
| 10 |
def extdoclink_role( |
| 11 |
name: str, # pylint: disable=unused-argument |
| 12 |
rawtext: str, |
| 13 |
text: str, |
| 14 |
lineno: int, # pylint: disable=unused-argument |
| 15 |
inliner: t.Any, # pylint: disable=unused-argument |
| 16 |
options: t.Any | None = None, # pylint: disable=unused-argument |
| 17 |
content: str | None = None, # pylint: disable=unused-argument |
| 18 |
) -> tuple[list[nodes.Node], list[t.Any]]: |
| 19 |
if " " not in text: |
| 20 |
raise ValueError("extdoclink role must contain space-separated text") |
| 21 |
linktext, _, ref = text.rpartition(" ") |
| 22 |
if not (ref.startswith("<") and ref.endswith(">")): |
| 23 |
raise ValueError("extdoclink role reference must be in angle brackets") |
| 24 |
ref = ref[1:-1] |
| 25 |
base_url = derive_doc_url_base(None) |
| 26 |
node = nodes.reference(rawtext, linktext, refuri=f"{base_url}/{ref}") |
| 27 |
return [node], [] |