Skip to content

Commit 23bcfbc

Browse files
committed
[DOCS] Document the :lines: option of literalinclude
Add the `:lines:` option to the reference page: syntax, that overlapping ranges are included once in the order of the file, that it is applied after the markers and therefore counts within the marked region, and what happens when the value selects nothing. Each of these was rendered and read back before being written down. Assisted-by: claude-code:claude-opus-5 Agent-Session: https://claude.ai/code/session_015QXXkquh2eQNBiTYA39Wss Signed-off-by: Sebastian Mendel <sebastian.mendel@netresearch.de>
1 parent b396703 commit 23bcfbc

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

docs/reference/restructuredtext/literalinclude.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,29 @@ publish the very content it was meant to exclude. The same happens when the mark
4747
when the ``end-before`` text occurs only above the line matched by ``start-after``. Rendering with ``--fail-on-log``
4848
turns any of these warnings into a failing build.
4949

50+
Selecting lines by number
51+
=========================
52+
53+
A region can also be selected by line number, which is useful for files that have no natural marker:
54+
55+
.. code-block::
56+
57+
.. literalinclude:: Example.php
58+
:language: php
59+
:lines: 1,3-5,20-
60+
61+
Line numbers start at 1, ranges are inclusive, and an omitted end means "down to the last line". Overlapping ranges
62+
are included once, in the order of the file.
63+
64+
``:lines:`` is applied *after* ``:start-after:`` and ``:end-before:``, so when they are combined the numbers count
65+
within the marked region rather than within the whole file.
66+
67+
Prefer markers where a file has them: line numbers change with every edit above the selected region, and nothing in
68+
the source file records that the documentation depends on them.
69+
70+
If the value cannot be read as a list of line numbers, or if it selects no line at all, a warning is logged and
71+
nothing is included.
72+
5073
Options
5174
=======
5275

@@ -62,6 +85,10 @@ Options
6285
``:end-before:``
6386
Text of the line the included region ends before. The line itself is not included.
6487

88+
``:lines:``
89+
Line numbers to be included, for example ``1,3-5,20-``. Counted within the region selected by ``start-after``
90+
and ``end-before``.
91+
6592
``:emphasize-lines:``
6693
Line numbers to be highlighted, for example ``3,5-6``. Counted within the included region.
6794

0 commit comments

Comments
 (0)