Markdown output for Sphinx based documentation

If you'd like to use pandoc why won't you simply change the Makefile Sphinx generates when you run sphinx-quickstart.py for the first time to convert the reStructuredText to Markdown?
It's the easiest solution, although Chris's solution should work as well if you incorporate it into the Makefile.


I didn't find anything which could take reStructuredText files and convert them to Markdown except for Pandoc, so I wrote a custom writer for Docutils (the reference implementation of reStructuredText and what Sphinx is built upon). The code is available on GitHub.

Note that it is only an initial implementation: it handles any reStructuredText document without error (tested against the standard.txt test document from the Docutils source repository) but many of the reStructuredText constructs (e.g. substitutions, raw directives etc.) are not supported and so not included in the Markdown output. I hope to add support for links, code blocks, images and tables: any help towards this is more than welcome - just go ahead and fork the code.

It seems that to add another writer/output format to Sphinx you need to add a "builder" using an extension.


Update Nov'18: sphinx-markdown-builder is now available - thanks to @Jam Risser :

Installation

pip3 install sphinx-markdown-builder

Dependencies

Python 3

Usage

Load extension in configuration.

conf.py

extensions = [
    'sphinx_markdown_builder'
]

If using recommonmark, make sure you explicitly ignore the build files as they will conflict with the system.

conf.py

exclude_patterns = [
    'build/*'
]

Build markdown files with Makefile

make markdown

Build markdown files with sphinx-build command

cd docs
sphinx-build -M markdown ./ build

References

  • https://github.com/codejamninja/sphinx-markdown-builder/
  • https://pypi.org/project/sphinx-markdown-builder/

ps. Outdated original answer (since sphinx-markdown-builder is now available): Created feature request for direct Markdown output support on Sphinx project site: https://github.com/sphinx-doc/sphinx/issues/4219 Thanks everyone who upvoted that github request - that made the difference!