summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Lykke Andersen <Jakob@caput.dk>2021-10-02 13:30:11 +0200
committerJakob Lykke Andersen <Jakob@caput.dk>2021-10-03 10:17:31 +0200
commit37083fcc1ab12fbc6d53213a92a132191eb79fc1 (patch)
tree5130cd07c1c745cd30933ea63d3a462074104a59
parentebea4327e3fe907477e2a3ed3a2ae3094103cf6e (diff)
downloadsphinx-git-37083fcc1ab12fbc6d53213a92a132191eb79fc1.tar.gz
js nodes, update display_prefix
-rw-r--r--CHANGES3
-rw-r--r--sphinx/domains/javascript.py19
-rw-r--r--tests/test_domain_js.py6
3 files changed, 19 insertions, 9 deletions
diff --git a/CHANGES b/CHANGES
index 4343ffb3e..b7feb8fa1 100644
--- a/CHANGES
+++ b/CHANGES
@@ -15,6 +15,9 @@ Incompatible changes
* #9672: the signature of
:py:meth:`domains.py.PyObject.get_signature_prefix` has changed to
return a list of nodes instead of a plain string.
+* ``domains.js.JSObject.display_prefix`` has been changed into a method
+ ``get_display_prefix`` which now returns a list of nodes
+ instead of a plain string.
Deprecated
----------
diff --git a/sphinx/domains/javascript.py b/sphinx/domains/javascript.py
index 565d681dc..7abfad482 100644
--- a/sphinx/domains/javascript.py
+++ b/sphinx/domains/javascript.py
@@ -41,9 +41,6 @@ class JSObject(ObjectDescription[Tuple[str, str]]):
#: added
has_arguments = False
- #: what is displayed right before the documentation entry
- display_prefix: str = None
-
#: If ``allow_nesting`` is ``True``, the object prefixes will be accumulated
#: based on directive nesting
allow_nesting = False
@@ -53,6 +50,10 @@ class JSObject(ObjectDescription[Tuple[str, str]]):
'noindexentry': directives.flag,
}
+ def get_display_prefix(self) -> List[nodes.Node]:
+ #: what is displayed right before the documentation entry
+ return []
+
def handle_signature(self, sig: str, signode: desc_signature) -> Tuple[str, str]:
"""Breaks down construct signatures
@@ -91,9 +92,9 @@ class JSObject(ObjectDescription[Tuple[str, str]]):
signode['object'] = prefix
signode['fullname'] = fullname
- if self.display_prefix:
- signode += addnodes.desc_annotation(self.display_prefix,
- self.display_prefix)
+ display_prefix = self.get_display_prefix()
+ if display_prefix:
+ signode += addnodes.desc_annotation('', '', *display_prefix)
if prefix:
signode += addnodes.desc_addname(prefix + '.', prefix + '.')
elif mod_name:
@@ -227,9 +228,13 @@ class JSCallable(JSObject):
class JSConstructor(JSCallable):
"""Like a callable but with a different prefix."""
- display_prefix = 'class '
+
allow_nesting = True
+ def get_display_prefix(self) -> List[nodes.Node]:
+ return [addnodes.desc_sig_keyword('class', 'class'),
+ addnodes.desc_sig_space()]
+
class JSModule(SphinxDirective):
"""
diff --git a/tests/test_domain_js.py b/tests/test_domain_js.py
index 1fb865d4b..535321d9f 100644
--- a/tests/test_domain_js.py
+++ b/tests/test_domain_js.py
@@ -15,7 +15,8 @@ from docutils import nodes
from sphinx import addnodes
from sphinx.addnodes import (desc, desc_annotation, desc_content, desc_name, desc_parameter,
- desc_parameterlist, desc_signature)
+ desc_parameterlist, desc_sig_keyword, desc_sig_space,
+ desc_signature)
from sphinx.domains.javascript import JavaScriptDomain
from sphinx.testing import restructuredtext
from sphinx.testing.util import assert_node
@@ -198,7 +199,8 @@ def test_js_class(app):
text = ".. js:class:: Application"
doctree = restructuredtext.parse(app, text)
assert_node(doctree, (addnodes.index,
- [desc, ([desc_signature, ([desc_annotation, "class "],
+ [desc, ([desc_signature, ([desc_annotation, ([desc_sig_keyword, 'class'],
+ desc_sig_space)],
[desc_name, "Application"],
[desc_parameterlist, ()])],
[desc_content, ()])]))