Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Markdown output for Sphinx based documentation [closed]

I found myself with a use case, where in addition to generating HTML and PDF from my Sphinx based documentation sources, I would also like to generate a Markdown version of the reStructuredText source files.

My preliminary research didn't find any core or extension support for this in Sphinx. Other than manually using pandoc or creating a new Sphinx extension for the task, is there be a simpler/more integrated solution for this?

like image 675
Pedro Romano Avatar asked Nov 15 '12 11:11

Pedro Romano


People also ask

Does Sphinx work with markdown?

To support Markdown-based documentation, Sphinx can use MyST-Parser. MyST-Parser is a Docutils bridge to markdown-it-py, a Python package for parsing the CommonMark Markdown flavor.

What is RST Sphinx?

reStructuredText is the default plaintext markup language used by Sphinx. This section is a brief introduction to reStructuredText (reST) concepts and syntax, intended to provide authors with enough information to author documents productively.

What is Maxdepth in Toctree?

A numeric maxdepth option may be given to indicate the depth of the tree; by default, all levels are included. [ 1] The representation of “TOC tree” is changed in each output format. The builders that output multiple files (ex. HTML) treat it as a collection of hyperlinks.


1 Answers

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.

like image 79
Chris Avatar answered Nov 13 '22 19:11

Chris