2

I am using for documenting a C code. I am not interested in features offered by , however I sometime would like to include some snippets from the code-base.

The .. literalinclude:: looks great, but the :lines: option is a bit weak especially if the code is edited afterwards.

I am thinking about a new option such as :marker-start: <<<HERE and :marker-end: <<<END.

What would be the easiest way to achieve this behavior?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
nowox
  • 25,978
  • 39
  • 143
  • 293

1 Answers1

4

You can use the start-after and end-before options. Below is an example.

example.txt:

# START
first line
second line
# END
third line

Markup:

.. literalinclude:: example.txt
   :start-after: # START
   :end-before: # END

This will appear in the output:

first line
second line

See https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-literalinclude.

mzjn
  • 48,958
  • 13
  • 128
  • 248