Added a :class:JSXRefRole which allows to display a method/attribute name only.

This commit is contained in:
Daniel Neuhäuser 2010-03-30 22:40:20 +00:00
parent 2331552a85
commit a791b7867b
2 changed files with 21 additions and 3 deletions

View File

@ -82,6 +82,23 @@ class JSCallable(JSObject):
"""Description of a JavaScript function, method or constructor."""
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):
"""JavaScript language domain."""
name = 'js'
@ -97,7 +114,7 @@ class JavaScriptDomain(Domain):
'attribute' : JSObject,
}
roles = {
'func': XRefRole(fix_parens=True),
'data': XRefRole(),
'attr': XRefRole()
'func': JSXRefRole(fix_parens=True),
'data': JSXRefRole(),
'attr': JSXRefRole()
}

View File

@ -103,6 +103,7 @@ Without target: :c:func:`CFunction`. :c:func:`!malloc`.
:js:data:`bar`
:js:func:`bar.baz()`
:js:func:`bar.baz`
:js:func:`~bar.baz()`
:js:attr:`bar.baz`