![]() The current RecommonMark specification on images [0] says that:  should render as <p><img src="/url" alt="foo" title="title" /></p> which means that "foo" should be the `alt` attribute, and "title" should be the `title` attribute. Currently, `recommonmark` will: 1. set the `alt` attribute to "title" 2. render "foo" as literal text following the image element. Neither yields results in line with the RecommonMark standard, resulting in the following when transformed to HTML: <p><img src="/url" alt="title" />foo</p> While it might be surprising that `alt` is set to "title", the more pressing issue is how the alt text becomes literal text within the paragraph, typically not rendering well. This commit instead makes `recommonmark`: 1. set the `alt` attribute to "foo" 2. drop "title" altogether since the `title` attribute is not supported in Docutils [1]. 1 coincides with the specification, and 2 is in my mind the least surprising solution within the capabilities of Docutils. The HTML will now be: <p><img src="/url" alt="foo" /></p> only differing in the missing `title` attribute when compared to the specification. [0]: https://spec.commonmark.org/0.28/#images [1]: http://docutils.sourceforge.net/docs/ref/rst/directives.html#image |
||
---|---|---|
docs | ||
recommonmark | ||
tests | ||
.gitignore | ||
.travis.yml | ||
CHANGELOG.md | ||
license.md | ||
MANIFEST.in | ||
prospector.yml | ||
README.md | ||
setup.cfg | ||
setup.py | ||
tox.ini |
recommonmark
A docutils
-compatibility bridge to CommonMark.
This allows you to write CommonMark inside of Docutils & Sphinx projects.
Documentation is available on Read the Docs: http://recommonmark.readthedocs.org
Contents
Getting Started
To use recommonmark
inside of Sphinx only takes 2 steps.
First you install it:
pip install recommonmark
Then add this to your Sphinx conf.py:
# for Sphinx-1.4 or newer
extensions = ['recommonmark']
# for Sphinx-1.3
from recommonmark.parser import CommonMarkParser
source_parsers = {
'.md': CommonMarkParser,
}
source_suffix = ['.rst', '.md']
This allows you to write both .md
and .rst
files inside of the same project.
Links
For all links in commonmark that aren't explicit URLs, they are treated as cross references with the :any:
role. This allows referencing a lot of things including files, labels, and even objects in the loaded domain.
AutoStructify
AutoStructify makes it possible to write your documentation in Markdown, and automatically convert this into rST at build time. See the AutoStructify Documentation for more information about configuration and usage.
To use the advanced markdown to rst transformations you must add AutoStructify
to your Sphinx conf.py.
# 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.
AutoStructify comes with the following options. See http://recommonmark.readthedocs.org/en/latest/auto_structify.html for more information about the specific features.
- 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.
- enable_auto_doc_ref: enable the Auto Doc Ref feature. Deprecated
- 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
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.
Why a bridge?
Many python tools (mostly for documentation creation) rely on docutils
.
But docutils only supports a ReStructuredText syntax.
For instance this issue and this StackOverflow
question show that there is an interest in allowing docutils
to use markdown as an alternative syntax.
Why another bridge to docutils?
recommonmark uses the python implementation of CommonMark while remarkdown implements a stand-alone parser leveraging parsley.
Both output a docutils
document tree and provide scripts
that leverage docutils
for generation of different types of documents.
Acknowledgement
recommonmark is mainly derived from remarkdown by Steve Genoud and leverages the python CommonMark implementation.
It was originally created by Luca Barbato, and is now maintained in the Read the Docs (rtfd) GitHub organization.