Merge pull request #8281 from tk0miya/8073_update_directive_example

docs: Fix an example for add_directive()
This commit is contained in:
Takeshi KOMIYA 2020-10-06 00:49:17 +09:00 committed by GitHub
commit c82d1c76e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -623,14 +623,14 @@ class Sphinx:
details, see `the Docutils docs details, see `the Docutils docs
<http://docutils.sourceforge.net/docs/howto/rst-directives.html>`_ . <http://docutils.sourceforge.net/docs/howto/rst-directives.html>`_ .
For example, the (already existing) :rst:dir:`literalinclude` directive For example, a custom directive named ``my-directive`` would be added
would be added like this: like this:
.. code-block:: python .. code-block:: python
from docutils.parsers.rst import Directive, directives from docutils.parsers.rst import Directive, directives
class LiteralIncludeDirective(Directive): class MyDirective(Directive):
has_content = True has_content = True
required_arguments = 1 required_arguments = 1
optional_arguments = 0 optional_arguments = 0
@ -643,7 +643,8 @@ class Sphinx:
def run(self): def run(self):
... ...
add_directive('literalinclude', LiteralIncludeDirective) def setup(app):
add_directive('my-directive', MyDirective)
If *override* is True, the given *cls* is forcedly installed even if If *override* is True, the given *cls* is forcedly installed even if
a directive named as *name* is already installed. a directive named as *name* is already installed.