Using Markdown with Sphynx¶
Yes, you can use Markdown files in Sphinx by using the recommonmark package. recommonmark is a Sphinx extension that allows you to use Markdown syntax in your .rst files.
Here’s how to use recommonmark:
1. Install recommonmark¶
Install the recommonmark package using pip:
pip install recommonmark
2. Add recommonmark to conf.py¶
In your conf.py file, add the following lines to enable recommonmark:
extensions = [
# Other extensions
'recommonmark',
]
# Add this line to allow Sphinx to parse Markdown
source_suffix = {
'.rst': 'restructuredtext',
'.md': 'markdown',
}
3. Use Markdown in .rst Files¶
You can now use Markdown syntax in your .rst files. Simply start your .rst file with the following line to indicate that it is a Markdown file:
.. include:: <(path-to-your-markdown-file).md>
:parser: markdown
You can also use Markdown in place of reStructuredText in your .rst files using the .. markdown:: directive. This can be useful if you want to include Markdown content within a reStructuredText file.
.. markdown::
# This is a heading
This is a paragraph with *italics* and **bold** text.
4. Build Your Documentation¶
Finally, build your documentation using Sphinx as you normally would:
make html
Your Markdown files will be processed by recommonmark and converted to HTML in your Sphinx documentation.
By using recommonmark, you can take advantage of the simplicity and ease-of-use of Markdown while still leveraging the power and flexibility of Sphinx for your documentation.