mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #8281 from tk0miya/8073_update_directive_example
docs: Fix an example for add_directive()
This commit is contained in:
commit
c82d1c76e1
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user