mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
js nodes, update display_prefix
This commit is contained in:
parent
ebea4327e3
commit
37083fcc1a
3
CHANGES
3
CHANGES
@ -15,6 +15,9 @@ Incompatible changes
|
|||||||
* #9672: the signature of
|
* #9672: the signature of
|
||||||
:py:meth:`domains.py.PyObject.get_signature_prefix` has changed to
|
:py:meth:`domains.py.PyObject.get_signature_prefix` has changed to
|
||||||
return a list of nodes instead of a plain string.
|
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
|
Deprecated
|
||||||
----------
|
----------
|
||||||
|
@ -41,9 +41,6 @@ class JSObject(ObjectDescription[Tuple[str, str]]):
|
|||||||
#: added
|
#: added
|
||||||
has_arguments = False
|
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
|
#: If ``allow_nesting`` is ``True``, the object prefixes will be accumulated
|
||||||
#: based on directive nesting
|
#: based on directive nesting
|
||||||
allow_nesting = False
|
allow_nesting = False
|
||||||
@ -53,6 +50,10 @@ class JSObject(ObjectDescription[Tuple[str, str]]):
|
|||||||
'noindexentry': directives.flag,
|
'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]:
|
def handle_signature(self, sig: str, signode: desc_signature) -> Tuple[str, str]:
|
||||||
"""Breaks down construct signatures
|
"""Breaks down construct signatures
|
||||||
|
|
||||||
@ -91,9 +92,9 @@ class JSObject(ObjectDescription[Tuple[str, str]]):
|
|||||||
signode['object'] = prefix
|
signode['object'] = prefix
|
||||||
signode['fullname'] = fullname
|
signode['fullname'] = fullname
|
||||||
|
|
||||||
if self.display_prefix:
|
display_prefix = self.get_display_prefix()
|
||||||
signode += addnodes.desc_annotation(self.display_prefix,
|
if display_prefix:
|
||||||
self.display_prefix)
|
signode += addnodes.desc_annotation('', '', *display_prefix)
|
||||||
if prefix:
|
if prefix:
|
||||||
signode += addnodes.desc_addname(prefix + '.', prefix + '.')
|
signode += addnodes.desc_addname(prefix + '.', prefix + '.')
|
||||||
elif mod_name:
|
elif mod_name:
|
||||||
@ -227,9 +228,13 @@ class JSCallable(JSObject):
|
|||||||
|
|
||||||
class JSConstructor(JSCallable):
|
class JSConstructor(JSCallable):
|
||||||
"""Like a callable but with a different prefix."""
|
"""Like a callable but with a different prefix."""
|
||||||
display_prefix = 'class '
|
|
||||||
allow_nesting = True
|
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):
|
class JSModule(SphinxDirective):
|
||||||
"""
|
"""
|
||||||
|
@ -15,7 +15,8 @@ from docutils import nodes
|
|||||||
|
|
||||||
from sphinx import addnodes
|
from sphinx import addnodes
|
||||||
from sphinx.addnodes import (desc, desc_annotation, desc_content, desc_name, desc_parameter,
|
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.domains.javascript import JavaScriptDomain
|
||||||
from sphinx.testing import restructuredtext
|
from sphinx.testing import restructuredtext
|
||||||
from sphinx.testing.util import assert_node
|
from sphinx.testing.util import assert_node
|
||||||
@ -198,7 +199,8 @@ def test_js_class(app):
|
|||||||
text = ".. js:class:: Application"
|
text = ".. js:class:: Application"
|
||||||
doctree = restructuredtext.parse(app, text)
|
doctree = restructuredtext.parse(app, text)
|
||||||
assert_node(doctree, (addnodes.index,
|
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_name, "Application"],
|
||||||
[desc_parameterlist, ()])],
|
[desc_parameterlist, ()])],
|
||||||
[desc_content, ()])]))
|
[desc_content, ()])]))
|
||||||
|
Loading…
Reference in New Issue
Block a user