Search code examples
restructuredtext

How to convert reStructuredText to plain text


I plan to use reStructuredText to write documentation with the main purpose of generating some nice HTML pages. For this I use the docutils rst2html.py tool.

However, I may also need to present the documentation in nice plain text format, that is without the reStructuredText markup, and where paragraph wrapping and similar nice formatting is still performed on the text output. But, there is no rst2txt.py tool in the docutils.

Is there a way to convert reStructuredText to nice plain text format, maybe with use of special options to docutils ?


Solution

  • Sphinx has a TextBuilder for txt output format. Just tried it and it seems to do what you are looking for.

    However, it might be a little outdated because it is not in the default Makefile. But it worked well on my fairly complex documentation (150 pdf pages). To use it, just add the following target to it:

    text:
        $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) _build/text
        @echo
        @echo "Build finished."
    

    Also, keep in mind that Sphinx implements only a subset of the rst specs.