mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Added a JavaScript domain and a js:function directive.
This commit is contained in:
@@ -107,7 +107,6 @@ In short:
|
||||
component of the target. For example, ``:py:meth:`~Queue.Queue.get``` will
|
||||
refer to ``Queue.Queue.get`` but only display ``get`` as the link text.
|
||||
|
||||
|
||||
The Python Domain
|
||||
-----------------
|
||||
|
||||
@@ -546,3 +545,14 @@ any domain:
|
||||
.. describe:: PAPER
|
||||
|
||||
You can set this variable to select a paper size.
|
||||
|
||||
The JavaScript Domain
|
||||
---------------------
|
||||
|
||||
The JavaScript domain (name **js**) provides the following directives:
|
||||
|
||||
.. directive:: .. js:function:: name(signature)
|
||||
|
||||
Describe a JavaScript function. If you want to document optional
|
||||
arguments use square brackets as :ref:`documented <signatures>` for Python
|
||||
signatures.
|
||||
|
||||
@@ -241,10 +241,12 @@ from sphinx.domains.c import CDomain
|
||||
from sphinx.domains.cpp import CPPDomain
|
||||
from sphinx.domains.std import StandardDomain
|
||||
from sphinx.domains.python import PythonDomain
|
||||
from sphinx.domains.javascript import JavaScriptDomain
|
||||
|
||||
BUILTIN_DOMAINS = {
|
||||
'std': StandardDomain,
|
||||
'py': PythonDomain,
|
||||
'c': CDomain,
|
||||
'cpp': CPPDomain
|
||||
'cpp': CPPDomain,
|
||||
"js": JavaScriptDomain,
|
||||
}
|
||||
|
||||
65
sphinx/domains/javascript.py
Normal file
65
sphinx/domains/javascript.py
Normal file
@@ -0,0 +1,65 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
sphinx.domains.javascript
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The JavaScript domain.
|
||||
|
||||
:copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
import re
|
||||
|
||||
from sphinx import addnodes
|
||||
from sphinx.domains import Domain, ObjType
|
||||
from sphinx.locale import l_, _
|
||||
from sphinx.directives import ObjectDescription
|
||||
from sphinx.domains.python import py_paramlist_re as js_paramlist_re
|
||||
|
||||
js_sig_re = re.compile(r'(\w+)\s*\((.*)\)')
|
||||
|
||||
class JSFunction(ObjectDescription):
|
||||
"""
|
||||
Description of a JavaScript function.
|
||||
"""
|
||||
def handle_signature(self, sig, signode):
|
||||
match = js_sig_re.match(sig)
|
||||
if match is None:
|
||||
raise ValueError()
|
||||
name, arglist = match.groups()
|
||||
|
||||
signode += addnodes.desc_name(name, name)
|
||||
if not arglist:
|
||||
signode += addnodes.desc_parameterlist()
|
||||
return name
|
||||
|
||||
stack = [signode[-1]]
|
||||
for token in js_paramlist_re.split(arglist):
|
||||
if token == '[':
|
||||
opt = addnodes.desc_optional()
|
||||
stack[-1] += opt
|
||||
stack.append(opt)
|
||||
elif token == ']':
|
||||
try:
|
||||
stack.pop()
|
||||
except IndexError:
|
||||
raise ValueError()
|
||||
elif not token or token == ',' or token.isspace():
|
||||
pass
|
||||
else:
|
||||
token = token.strip()
|
||||
stack[-1] += addnodes.desc_parameter(token, token)
|
||||
if len(stack) != 1:
|
||||
raise ValueError()
|
||||
return name
|
||||
|
||||
class JavaScriptDomain(Domain):
|
||||
"""JavaScript language domain."""
|
||||
name = "js"
|
||||
label= "JavaScript"
|
||||
object_types = {
|
||||
"function": ObjType(l_("js function"), "func"),
|
||||
}
|
||||
directives = {
|
||||
"function": JSFunction,
|
||||
}
|
||||
@@ -73,6 +73,12 @@ C items
|
||||
.. c:var:: sphinx_global
|
||||
|
||||
|
||||
Javascript items
|
||||
================
|
||||
|
||||
.. js:function:: foo()
|
||||
|
||||
|
||||
References
|
||||
==========
|
||||
|
||||
|
||||
Reference in New Issue
Block a user