2014-10-17 22:29:41 +02:00
# recommonmark
2013-08-25 17:06:26 +02:00
2015-07-28 11:15:59 -07:00
A `docutils` -compatibility bridge to [CommonMark][cm].
This allows you to write CommonMark inside of Docutils & Sphinx projects.
2013-08-25 16:45:13 +02:00
2015-10-19 10:55:58 -07:00
Documentation is available on Read the Docs: < http: / / recommonmark . readthedocs . org >
2015-10-19 14:13:45 -07:00
Contents
--------
2017-03-03 01:20:23 -08:00
2015-10-19 14:13:45 -07:00
* [API Reference ](api_ref.md )
* [AutoStructify Component ](auto_structify.md )
2015-10-19 10:55:58 -07:00
## Getting Started
To use `recommonmark` inside of Sphinx only takes 2 steps.
First you install it:
2015-10-20 16:13:16 -07:00
```
2015-10-29 23:19:12 +01:00
pip install recommonmark
2015-10-20 16:13:16 -07:00
```
2015-10-19 10:55:58 -07:00
Then add this to your Sphinx conf.py:
2015-10-20 16:13:16 -07:00
```
2015-10-29 23:19:12 +01:00
from recommonmark.parser import CommonMarkParser
2015-10-19 10:55:58 -07:00
2015-10-29 23:19:12 +01:00
source_parsers = {
'.md': CommonMarkParser,
}
2015-10-19 10:55:58 -07:00
2015-10-29 23:19:12 +01:00
source_suffix = ['.rst', '.md']
2015-10-20 16:13:16 -07:00
```
2015-08-23 15:19:28 -07:00
2015-10-19 10:58:26 -07:00
This allows you to write both `.md` and `.rst` files inside of the same project.
2017-02-23 16:45:27 -06:00
### Links
For all links in commonmark that aren't explicit URLs, they are treated as cross references with the [`:any:` ](http://www.sphinx-doc.org/en/stable/markup/inline.html#role-any ) role. This allows referencing a lot of things including files, labels, and even objects in the loaded domain.
2016-03-10 15:36:12 -05:00
### AutoStructify
2018-02-10 08:41:14 -08:00
AutoStructify makes it possible to write your documentation in Markdown, and automatically convert this
into rST at build time. See [the AutoStructify Documentation ](http://recommonmark.readthedocs.org/en/latest/auto_structify.html )
for more information about configuration and usage.
2016-03-10 15:36:12 -05:00
To use the advanced markdown to rst transformations you must add `AutoStructify` to your Sphinx conf.py.
```python
# At top on conf.py (with other import statements)
import recommonmark
from recommonmark.transform import AutoStructify
# At the bottom of conf.py
def setup(app):
app.add_config_value('recommonmark_config', {
'url_resolver': lambda url: github_doc_root + url,
'auto_toc_tree_section': 'Contents',
}, True)
app.add_transform(AutoStructify)
```
See https://github.com/rtfd/recommonmark/blob/master/docs/conf.py for a full example.
2018-02-10 08:41:14 -08:00
AutoStructify comes with the following options. See [http://recommonmark.readthedocs.org/en/latest/auto_structify.html ](http://recommonmark.readthedocs.org/en/latest/auto_structify.html ) for more information about the specific features.
2016-03-10 15:36:12 -05:00
2016-03-10 15:41:39 -05:00
* __enable_auto_toc_tree__: enable the Auto Toc Tree feature.
* __auto_toc_tree_section__: when True, Auto Toc Tree will only be enabled on section that matches the title.
2017-03-03 01:20:23 -08:00
* __enable_auto_doc_ref__: enable the Auto Doc Ref feature. **Deprecated**
2016-03-10 15:41:39 -05:00
* __enable_math__: enable the Math Formula feature.
* __enable_inline_math__: enable the Inline Math feature.
* __enable_eval_rst__: enable the evaluate embedded reStructuredText feature.
* __url_resolver__: a function that maps a existing relative position in the document to a http link
2016-03-10 15:36:12 -05:00
2015-10-19 14:13:45 -07:00
## Development
You can run the tests by running `tox` in the top-level of the project.
We are working to expand test coverage,
but this will at least test basic Python 2 and 3 compatability.
2014-10-17 22:29:41 +02:00
## Why a bridge?
2013-08-25 16:45:13 +02:00
2014-10-17 22:29:41 +02:00
Many python tools (mostly for documentation creation) rely on `docutils` .
But [docutils][dc] only supports a ReStructuredText syntax.
2013-08-25 16:45:13 +02:00
2014-10-17 22:29:41 +02:00
For instance [this issue][sphinx-issue] and [this StackOverflow
question][so-question] show that there is an interest in allowing `docutils`
to use markdown as an alternative syntax.
2013-08-25 16:45:13 +02:00
2014-10-17 22:29:41 +02:00
## Why another bridge to docutils?
2013-08-25 16:45:13 +02:00
2014-10-17 22:29:41 +02:00
recommonmark uses the [python implementation][pcm] of [CommonMark][cm] while
[remarkdown][rmd] implements a stand-alone parser leveraging [parsley][prs].
2013-08-25 16:45:13 +02:00
2014-10-17 22:29:41 +02:00
Both output a [`docutils` document tree][dc] and provide scripts
that leverage `docutils` for generation of different types of documents.
2013-08-25 16:45:13 +02:00
2014-10-17 22:29:41 +02:00
## Acknowledgement
2013-08-25 16:45:13 +02:00
2014-10-17 22:29:41 +02:00
recommonmark is mainly derived from [remarkdown][rmd] by Steve Genoud and
leverages the python CommonMark implementation.
2013-08-25 16:45:13 +02:00
2015-07-28 11:12:27 -07:00
It was originally created by [Luca Barbato][lu-zero],
and is now maintained in the Read the Docs (rtfd) GitHub organization.
2015-07-28 10:44:19 -07:00
2014-10-17 22:29:41 +02:00
[cm]: http://commonmark.org
2016-02-07 19:11:06 +03:00
[pcm]: https://github.com/rtfd/CommonMark-py
2014-10-17 22:29:41 +02:00
[rmd]: https://github.com/sgenoud/remarkdown
[prs]: https://github.com/python-parsley/parsley
2015-07-28 10:44:19 -07:00
[lu-zero]: https://github.com/lu-zero
2013-08-25 16:45:13 +02:00
2014-10-17 22:29:41 +02:00
[dc]: http://docutils.sourceforge.net/docs/ref/doctree.html
[sphinx-issue]: https://bitbucket.org/birkenfeld/sphinx/issue/825/markdown-capable-sphinx
[so-question]: http://stackoverflow.com/questions/2471804/using-sphinx-with-markdown-instead-of-rst