1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
"""Override MyST’s cite role with one that works."""
from __future__ import annotations
from types import MappingProxyType
from typing import TYPE_CHECKING
from docutils import nodes, utils
if TYPE_CHECKING:
from collections.abc import Mapping, Sequence
from typing import Any
from docutils.parsers.rst.states import Inliner
from sphinx.application import Sphinx
def cite_role( # noqa: PLR0917
name: str,
rawsource: str,
text: str,
lineno: int,
inliner: Inliner,
options: Mapping[str, Any] = MappingProxyType({}),
content: Sequence[str] = (),
) -> tuple[list[nodes.Node], list[nodes.system_message]]:
key = utils.unescape(text)
node = nodes.citation_reference(f"[{key}]_", key)
return [node], []
def setup(app: Sphinx):
app.add_role("cite", cite_role, override=True)
|