diff --git a/functests/roots/test-default/index.rst b/functests/roots/test-default/index.rst index da8889d..f46ab71 100644 --- a/functests/roots/test-default/index.rst +++ b/functests/roots/test-default/index.rst @@ -6,3 +6,4 @@ Using node modules ================== * :npm:`react` +* :pypi:`sphinx-revealjs` diff --git a/functests/test_sphinx.py b/functests/test_sphinx.py index 0edcd06..c1a78f7 100644 --- a/functests/test_sphinx.py +++ b/functests/test_sphinx.py @@ -10,3 +10,4 @@ def test_work_on_sphinx(app: SphinxTestApp): index_html = app.outdir / "index.html" assert index_html.exists() assert "https://www.npmjs.com/package/react" in index_html.read_text() + assert "https://pypi.org/project/sphinx-revealjs" in index_html.read_text() diff --git a/src/rst_multi_refs/registry/pypi.py b/src/rst_multi_refs/registry/pypi.py new file mode 100644 index 0000000..927d25c --- /dev/null +++ b/src/rst_multi_refs/registry/pypi.py @@ -0,0 +1,26 @@ +"""PyPI registry refecence module.""" +from typing import List, Optional + +from docutils import nodes +from docutils.parsers.rst import roles +from docutils.parsers.rst.states import Inliner + + +def reference_role( + role: str, + rawtext: str, + text: str, + lineno: int, + inliner: Inliner, + options: Optional[dict] = None, + content: Optional[List[str]] = None, +): + """Parser.""" + options = roles.normalized_role_options(options) + messages = [] + url = f"https://pypi.org/project/{text}" + return [nodes.reference(rawtext, text, refuri=url, **options)], messages + + +def setup(): # noqa: D103 + roles.register_canonical_role("pypi", reference_role)