Commits

Anonymous committed 98410d1

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

  • Participants
  • Parent commits 3f5b22b

Comments (0)

Files changed (2)

sphinx/domains/javascript.py

     """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'
         'attribute' : JSObject,
     }
     roles = {
-        'func': XRefRole(fix_parens=True),
-        'data': XRefRole(),
-        'attr': XRefRole()
+        'func': JSXRefRole(fix_parens=True),
+        'data': JSXRefRole(),
+        'attr': JSXRefRole()
     }

tests/root/objects.txt

 :js:data:`bar`
 :js:func:`bar.baz()`
 :js:func:`bar.baz`
+:js:func:`~bar.baz()`
 
 :js:attr:`bar.baz`