summaryrefslogtreecommitdiff
path: root/doc/markup/code.rst
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-02-23 19:24:02 +0100
committerGeorg Brandl <georg@python.org>2009-02-23 19:24:02 +0100
commit5591c550266c6911ab686f96d02eb5b68a9378ad (patch)
treeebc82048ec18a2b95530ef0f20d660176e374a29 /doc/markup/code.rst
parent55c0b7ca30c1c29885562684944a33b32dd7fabe (diff)
parent8041e28a58f85edac09ce74722a656f09de95a78 (diff)
downloadsphinx-5591c550266c6911ab686f96d02eb5b68a9378ad.tar.gz
merge with 0.5
Diffstat (limited to 'doc/markup/code.rst')
-rw-r--r--doc/markup/code.rst29
1 files changed, 28 insertions, 1 deletions
diff --git a/doc/markup/code.rst b/doc/markup/code.rst
index 6b2fbd02..28f75236 100644
--- a/doc/markup/code.rst
+++ b/doc/markup/code.rst
@@ -104,7 +104,7 @@ Includes
The directive also supports the ``linenos`` flag option to switch on line
numbers, and a ``language`` option to select a language different from the
current file's standard language. Example with options::
-
+
.. literalinclude:: example.rb
:language: ruby
:linenos:
@@ -116,8 +116,35 @@ Includes
.. literalinclude:: example.py
:encoding: latin-1
+ The directive also supports including only parts of the file. If it is a
+ Python module, you can select a class, function or method to include using
+ the ``pyobject`` option::
+
+ .. literalinclude:: example.py
+ :pyobject: Timer.start
+
+ This would only include the code lines belonging to the ``start()`` method in
+ the ``Timer`` class within the file.
+
+ Alternately, you can specify exactly which lines to include by giving a
+ ``lines`` option::
+
+ .. literalinclude:: example.py
+ :lines: 1,3,5-10,20-
+
+ This includes the lines 1, 3, 5 to 10 and lines 20 to the last line.
+
+ Another way to control which part of the file is included is to use the
+ ``start-after`` and ``end-before`` options (or only one of them). If
+ ``start-after`` is given as a string option, only lines that follow the first
+ line containing that string are included. If ``end-before`` is given as a
+ string option, only lines that precede the first lines containing that string
+ are included.
+
.. versionadded:: 0.4.3
The ``encoding`` option.
+ .. versionadded:: 0.6
+ The ``pyobject``, ``lines``, ``start-after`` and ``end-before`` options.
.. rubric:: Footnotes