Skip to content

Commit

Permalink
Allow extensions to define the keys returned by linkcode ext
Browse files Browse the repository at this point in the history
  • Loading branch information
n-peugnet committed Dec 30, 2023
1 parent 23c9cb4 commit 727787b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions doc/extdev/appapi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ package.

.. automethod:: Sphinx.add_autodoc_attrgetter

.. automethod:: Sphinx.add_linkcode_domain

.. automethod:: Sphinx.add_search_language

.. automethod:: Sphinx.add_source_suffix
Expand Down
9 changes: 9 additions & 0 deletions sphinx/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,15 @@ def add_autodoc_attrgetter(self, typ: type, getter: Callable[[Any, str, Any], An
logger.debug('[app] adding autodoc attrgetter: %r', (typ, getter))
self.registry.add_autodoc_attrgetter(typ, getter)

def add_linkcode_domain(self, domain: str, keys: list[str]) -> None:
"""Register a new list of keys to use for a domain by the
:mod:`sphinx.ext.linkcode` extension.
.. versionadded:: 7.3
"""
from sphinx.ext.linkcode import domain_keys
domain_keys[domain] = keys

def add_search_language(self, cls: Any) -> None:
"""Register a new language for the HTML search index.
Expand Down
15 changes: 8 additions & 7 deletions sphinx/ext/linkcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
from sphinx.application import Sphinx


domain_keys = {
'py': ['module', 'fullname'],
'c': ['names'],
'cpp': ['names'],
'js': ['object', 'fullname'],
}


class LinkcodeError(SphinxError):
category = "linkcode error"

Expand All @@ -30,13 +38,6 @@ def doctree_read(app: Sphinx, doctree: Node) -> None:
raise LinkcodeError(msg)
assert resolve_target is not None # for mypy

domain_keys = {
'py': ['module', 'fullname'],
'c': ['names'],
'cpp': ['names'],
'js': ['object', 'fullname'],
}

for objnode in list(doctree.findall(addnodes.desc)):
domain = objnode.get('domain')
uris: set[str] = set()
Expand Down

0 comments on commit 727787b

Please sign in to comment.