Skip to content

Instantly share code, notes, and snippets.

@shaypal5
Last active March 28, 2023 17:08
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaypal5/70044eeda587fae17b180e723496b057 to your computer and use it in GitHub Desktop.
Save shaypal5/70044eeda587fae17b180e723496b057 to your computer and use it in GitHub Desktop.
Including parts of README.rst in your sphinx docs

Taken from a post by Stuart Colville at https://muffinresearch.co.uk/selectively-including-parts-readme-rst-in-your-docs/. Here only to make this star-able by myself.

In your README.rst add a marker marking from which point you want to start importing content:

Blah blah project  
=================

Here's all the actual readme content.

.. inclusion-marker-do-not-remove

My Awesome content I wish to include  
------------------------------------

Blah blah etc etc.

And then in any rst file that is part of your sphinx documentation you can include the above content using:

.. include:: ../../README.rst
  :start-after: inclusion-marker-do-not-remove

Where the ../../README.rst path assumes the file you wish to include your README contents in is at your_package/docs/source. Adapt it accordingly if this is not the case.

@bitranox
Copy link

bitranox commented May 3, 2019

I made a script to process the rst includes to import those includes and assemble the result into a monolythic RST File that can be rendered on Github.

Even nested includes are possible (call the build script multiple times), and all the include options like start-after, end-before, etc ...

So You can include code snippets, requirements, or other *.rst or txt Files and test the documentation build even on travis.

The script is shell friendly, supports piping and offers additional some string replacement function. It also has a very good error reporting (for instance when some :start-after: marker is not found, etc ...) showing You exactly on which line-number in which file the error occured.

I use it myself to include tested code snippets into the documentation, and build the documentation on travis automatically, before deploying to PyPi

Check it out, it might be useful !

https://github.com/bitranox...

Yours sincerely

Robert / Vienna

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment