diff options
| author | Rapptz <[email protected]> | 2020-12-19 00:48:35 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2020-12-19 00:48:35 -0500 |
| commit | 2a6ea3532b3ec3d75e560fe1a9fe76b29566108b (patch) | |
| tree | e6b56c3ebd890a24180824bc6c9b45b6cb0a8a44 /docs/extensions | |
| parent | [commands] Make documentation use new attributetable (diff) | |
| download | discord.py-2a6ea3532b3ec3d75e560fe1a9fe76b29566108b.tar.xz discord.py-2a6ea3532b3ec3d75e560fe1a9fe76b29566108b.zip | |
Rework index page to take less vertical space
Diffstat (limited to 'docs/extensions')
| -rw-r--r-- | docs/extensions/resourcelinks.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/docs/extensions/resourcelinks.py b/docs/extensions/resourcelinks.py new file mode 100644 index 00000000..f2e13298 --- /dev/null +++ b/docs/extensions/resourcelinks.py @@ -0,0 +1,44 @@ +# Credit to sphinx.ext.extlinks for being a good starter +# Copyright 2007-2020 by the Sphinx team +# Licensed under BSD. + +from typing import Any, Dict, List, Tuple + +from docutils import nodes, utils +from docutils.nodes import Node, system_message +from docutils.parsers.rst.states import Inliner + +import sphinx +from sphinx.application import Sphinx +from sphinx.util.nodes import split_explicit_title +from sphinx.util.typing import RoleFunction + + +def make_link_role(resource_links: Dict[str, str]) -> RoleFunction: + def role( + typ: str, + rawtext: str, + text: str, + lineno: int, + inliner: Inliner, + options: Dict = {}, + content: List[str] = [] + ) -> Tuple[List[Node], List[system_message]]: + + text = utils.unescape(text) + has_explicit_title, title, key = split_explicit_title(text) + full_url = resource_links[key] + if not has_explicit_title: + title = full_url + pnode = nodes.reference(title, title, internal=False, refuri=full_url) + return [pnode], [] + return role + + +def add_link_role(app: Sphinx) -> None: + app.add_role('resource', make_link_role(app.config.resource_links)) + +def setup(app: Sphinx) -> Dict[str, Any]: + app.add_config_value('resource_links', {}, 'env') + app.connect('builder-inited', add_link_role) + return {'version': sphinx.__display_version__, 'parallel_read_safe': True} |