diff options
author | Stephen Finucane <stephen@that.guru> | 2019-02-08 17:03:09 +0000 |
---|---|---|
committer | Stephen Finucane <stephen@that.guru> | 2019-02-09 17:58:30 +0000 |
commit | 93081e2fce3a7795ddbc23fb4f1df9224f17d3fc (patch) | |
tree | 8f871af32ab165a1f56ecb08e4f2e8914eacbffa /doc/development/tutorials/helloworld.rst | |
parent | 513d99c316055f63d77aa3c2c1b9ec73b277d426 (diff) | |
download | sphinx-git-93081e2fce3a7795ddbc23fb4f1df9224f17d3fc.tar.gz |
doc: Use 'literalinclude' directive for examples
This avoid duplication and could conceivably let us test this stuff in
code later on.
Signed-off-by: Stephen Finucane <stephen@that.guru>
Diffstat (limited to 'doc/development/tutorials/helloworld.rst')
-rw-r--r-- | doc/development/tutorials/helloworld.rst | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/doc/development/tutorials/helloworld.rst b/doc/development/tutorials/helloworld.rst index b73a12cb0..857b86c9a 100644 --- a/doc/development/tutorials/helloworld.rst +++ b/doc/development/tutorials/helloworld.rst @@ -55,22 +55,9 @@ Writing the extension Open :file:`helloworld.py` and paste the following code in it: -.. code-block:: python - - from docutils import nodes - from docutils.parsers.rst import Directive - - - class HelloWorld(Directive): - - def run(self): - paragraph_node = nodes.paragraph(text='Hello World!') - return [paragraph_node] - - - def setup(app): - app.add_directive("helloworld", HelloWorld) - +.. literalinclude:: examples/helloworld.py + :language: python + :linenos: Some essential things are happening in this example, and you will see them for all directives. @@ -79,13 +66,10 @@ all directives. Our new directive is declared in the ``HelloWorld`` class. -.. code-block:: python - - class HelloWorld(Directive): - - def run(self): - paragraph_node = nodes.paragraph(text='Hello World!') - return [paragraph_node] +.. literalinclude:: examples/helloworld.py + :language: python + :linenos: + :lines: 5-9 This class extends the docutils_' ``Directive`` class. All extensions that create directives should extend this class. @@ -115,10 +99,10 @@ the ``text`` parameter. This function is a requirement. We use it to plug our new directive into Sphinx. -.. code-block:: python - - def setup(app): - app.add_directive("helloworld", HelloWorld) +.. literalinclude:: examples/helloworld.py + :language: python + :linenos: + :lines: 12- The simplest thing you can do it call the :meth:`~Sphinx.add_directive` method, which is what we've done here. For this particular call, the first |