-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for refer to PyPI packages
- Loading branch information
Showing
3 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ Using node modules | |
================== | ||
|
||
* :npm:`react` | ||
* :pypi:`sphinx-revealjs` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |