mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Added a :class:JSXRefRole
which allows to display a method/attribute name only.
This commit is contained in:
parent
2331552a85
commit
a791b7867b
@ -82,6 +82,23 @@ class JSCallable(JSObject):
|
|||||||
"""Description of a JavaScript function, method or constructor."""
|
"""Description of a JavaScript function, method or constructor."""
|
||||||
has_arguments = True
|
has_arguments = True
|
||||||
|
|
||||||
|
class JSXRefRole(XRefRole):
|
||||||
|
def process_link(self, env, refnode, has_explicit_title, title, target):
|
||||||
|
# basically what sphinx.domains.python.PyXRefRole does
|
||||||
|
refnode['js:object'] = env.temp_data.get('js:object')
|
||||||
|
if not has_explicit_title:
|
||||||
|
title = title.lstrip('.')
|
||||||
|
target = target.lstrip('~')
|
||||||
|
if title[0:1] == '~':
|
||||||
|
title = title[1:]
|
||||||
|
dot = title.rfind('.')
|
||||||
|
if dot != -1:
|
||||||
|
title = title[dot+1:]
|
||||||
|
if target[0:1] == '.':
|
||||||
|
target = target[1:]
|
||||||
|
refnode['refspecific'] = True
|
||||||
|
return title, target
|
||||||
|
|
||||||
class JavaScriptDomain(Domain):
|
class JavaScriptDomain(Domain):
|
||||||
"""JavaScript language domain."""
|
"""JavaScript language domain."""
|
||||||
name = 'js'
|
name = 'js'
|
||||||
@ -97,7 +114,7 @@ class JavaScriptDomain(Domain):
|
|||||||
'attribute' : JSObject,
|
'attribute' : JSObject,
|
||||||
}
|
}
|
||||||
roles = {
|
roles = {
|
||||||
'func': XRefRole(fix_parens=True),
|
'func': JSXRefRole(fix_parens=True),
|
||||||
'data': XRefRole(),
|
'data': JSXRefRole(),
|
||||||
'attr': XRefRole()
|
'attr': JSXRefRole()
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,7 @@ Without target: :c:func:`CFunction`. :c:func:`!malloc`.
|
|||||||
:js:data:`bar`
|
:js:data:`bar`
|
||||||
:js:func:`bar.baz()`
|
:js:func:`bar.baz()`
|
||||||
:js:func:`bar.baz`
|
:js:func:`bar.baz`
|
||||||
|
:js:func:`~bar.baz()`
|
||||||
|
|
||||||
:js:attr:`bar.baz`
|
:js:attr:`bar.baz`
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user