mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Automatically convert directive functions, and add a test for that.
This commit is contained in:
parent
414816bb37
commit
213eba0225
@ -18,7 +18,8 @@ from os import path
|
|||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
from docutils.parsers.rst import Directive, directives, roles
|
from docutils.parsers.rst import Directive, convert_directive_function, \
|
||||||
|
directives, roles
|
||||||
|
|
||||||
import sphinx
|
import sphinx
|
||||||
from sphinx import package_dir, locale
|
from sphinx import package_dir, locale
|
||||||
@ -341,9 +342,9 @@ class Sphinx(object):
|
|||||||
return obj
|
return obj
|
||||||
else:
|
else:
|
||||||
obj.content = content
|
obj.content = content
|
||||||
obj.arguments = arguments
|
obj.arguments = arguments or (0, 0, False)
|
||||||
obj.options = options
|
obj.options = options
|
||||||
return obj
|
return convert_directive_function(obj)
|
||||||
|
|
||||||
def add_directive(self, name, obj, content=None, arguments=None, **options):
|
def add_directive(self, name, obj, content=None, arguments=None, **options):
|
||||||
directives.register_directive(
|
directives.register_directive(
|
||||||
|
@ -112,7 +112,6 @@ class Domain(object):
|
|||||||
if name not in self.directives:
|
if name not in self.directives:
|
||||||
return None
|
return None
|
||||||
fullname = '%s:%s' % (self.name, name)
|
fullname = '%s:%s' % (self.name, name)
|
||||||
# XXX what about function-style directives?
|
|
||||||
BaseDirective = self.directives[name]
|
BaseDirective = self.directives[name]
|
||||||
class DirectiveAdapter(BaseDirective):
|
class DirectiveAdapter(BaseDirective):
|
||||||
def run(self):
|
def run(self):
|
||||||
|
@ -58,7 +58,12 @@ autosummary_generate = ['autosummary']
|
|||||||
# modify tags from conf.py
|
# modify tags from conf.py
|
||||||
tags.add('confpytag')
|
tags.add('confpytag')
|
||||||
|
|
||||||
|
|
||||||
|
# -- extension API
|
||||||
|
|
||||||
|
from docutils import nodes
|
||||||
from sphinx import addnodes
|
from sphinx import addnodes
|
||||||
|
from sphinx.util.compat import Directive
|
||||||
|
|
||||||
def userdesc_parse(env, sig, signode):
|
def userdesc_parse(env, sig, signode):
|
||||||
x, y = sig.split(':')
|
x, y = sig.split(':')
|
||||||
@ -67,7 +72,18 @@ def userdesc_parse(env, sig, signode):
|
|||||||
signode[-1] += addnodes.desc_parameter(y, y)
|
signode[-1] += addnodes.desc_parameter(y, y)
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
def functional_directive(name, arguments, options, content, lineno,
|
||||||
|
content_offset, block_text, state, state_machine):
|
||||||
|
return [nodes.strong(text='from function: %s' % options['opt'])]
|
||||||
|
|
||||||
|
class ClassDirective(Directive):
|
||||||
|
option_spec = {'opt': lambda x: x}
|
||||||
|
def run(self):
|
||||||
|
return [nodes.strong(text='from class: %s' % self.options['opt'])]
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
app.add_config_value('value_from_conf_py', 42, False)
|
app.add_config_value('value_from_conf_py', 42, False)
|
||||||
|
app.add_directive('funcdir', functional_directive, opt=lambda x: x)
|
||||||
|
app.add_directive('clsdir', ClassDirective)
|
||||||
app.add_description_unit('userdesc', 'userdescrole', '%s (userdesc)',
|
app.add_description_unit('userdesc', 'userdescrole', '%s (userdesc)',
|
||||||
userdesc_parse)
|
userdesc_parse)
|
||||||
|
@ -11,6 +11,7 @@ Contents:
|
|||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
:numbered:
|
:numbered:
|
||||||
|
|
||||||
|
extapi
|
||||||
images
|
images
|
||||||
subdir/images
|
subdir/images
|
||||||
subdir/includes
|
subdir/includes
|
||||||
|
10
tests/root/extapi.txt
Normal file
10
tests/root/extapi.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
Extension API tests
|
||||||
|
===================
|
||||||
|
|
||||||
|
Testing directives:
|
||||||
|
|
||||||
|
.. funcdir::
|
||||||
|
:opt: Foo
|
||||||
|
|
||||||
|
.. clsdir::
|
||||||
|
:opt: Bar
|
@ -66,6 +66,10 @@ HTML_XPATH = {
|
|||||||
".//dt[@id='test_autodoc.function']/em": r'\*\*kwds',
|
".//dt[@id='test_autodoc.function']/em": r'\*\*kwds',
|
||||||
".//dd": r'Return spam\.',
|
".//dd": r'Return spam\.',
|
||||||
},
|
},
|
||||||
|
'extapi.html': {
|
||||||
|
".//strong": 'from function: Foo',
|
||||||
|
".//strong": 'from class: Bar',
|
||||||
|
},
|
||||||
'markup.html': {
|
'markup.html': {
|
||||||
".//title": 'set by title directive',
|
".//title": 'set by title directive',
|
||||||
".//p/em": 'Section author: Georg Brandl',
|
".//p/em": 'Section author: Georg Brandl',
|
||||||
|
Loading…
Reference in New Issue
Block a user