From aa1073cfe184c11f8b65900c205056c3ad408786 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 27 Mar 2018 23:10:22 +0900 Subject: [PATCH] Fix #4787: Update docstrings for add_directive() --- sphinx/application.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/sphinx/application.py b/sphinx/application.py index 8014460a3..250c456ec 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -671,7 +671,7 @@ class Sphinx(object): function and determine whether the directive has content, arguments and options, respectively. **This style is deprecated.** - - In the docutils 0.5 style, *directiveclass* is the directive class. + - In the docutils 0.5 style, *obj* is the directive class. It must already have attributes named *has_content*, *required_arguments*, *optional_arguments*, *final_argument_whitespace* and *option_spec* that correspond to the @@ -687,12 +687,22 @@ class Sphinx(object): .. code-block:: python - from docutils.parsers.rst import directives - add_directive('literalinclude', literalinclude_directive, - content = 0, arguments = (1, 0, 0), - linenos = directives.flag, - language = directives.unchanged, - encoding = directives.encoding) + from docutils.parsers.rst import Directive, directives + + class LiteralIncludeDirective(Directive): + has_content = True + required_arguments = 1 + optional_arguments = 0 + final_argument_whitespace = True + option_spec = { + 'class': directives.class_option, + 'name': directives.unchanged, + } + + def run(self): + ... + + add_directive('literalinclude', LiteralIncludeDirective) .. versionchanged:: 0.6 Docutils 0.5-style directive classes are now supported.