Add start-after and end-before fields to literalinclude

Dmitriy Morozov avatarDmitriy Morozov created an issue

It would be nice if literalinclude directive understood fields start-after and end-before like rst's normal include directive. It would be even better to also have start-after-line and end-before-line directives that would behave the same way, but would skip the line containing the occurrence of the parameter. So that if one had the following two files

sample.py ...

  1. example of quicksort ...
  2. end example of quicksort ...

sample.rst ... .. literalinclude:: sample.py :start-after-line: quicksort :end-before-line: quicksort

The output would be the code snipped with the example.

Comments (5)

  1. Dmitriy Morozov

    Man, did I screw up with the formatting. Here are the snippets.

    sample.py

    ...
    # example of quicksort
    ...
    # end example of quicksort
    ...
    

    sample.rst

    ...
    
    .. literalinclude:: sample.py
       :start-after-line: quicksort
       :end-before-line: quicksort
    
  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.