No description
Find a file
Valentin Boettcher 55ac935fb1 fix inline math
2019-08-27 13:58:59 +02:00
docs Add cross-reference labeling. 2019-08-22 17:28:00 +02:00
recommonmark fix inline math 2019-08-27 13:58:59 +02:00
tests Merge pull request #166 from gibfahn/allow_overwriting_link_schemes 2019-08-09 11:18:54 -07:00
.gitignore Add node_modules to gitignore 2019-08-09 11:30:59 -07:00
.travis.yml Run travis against multiple sphinx versions 2018-10-12 10:54:50 +02:00
CHANGELOG.md Setup release 0.6.0 2019-08-09 11:16:58 -07:00
license.md Create license.md 2014-10-14 11:32:29 +02:00
MANIFEST.in Include all test files in PyPI tarball 2019-01-14 14:52:21 +01:00
prospector.yml Stop linting since there's a lot of errors for now. 2018-04-27 09:33:14 -07:00
README.md Add cross-reference labeling. 2019-08-22 17:28:00 +02:00
setup.cfg Setup release 0.6.0 2019-08-09 11:16:58 -07:00
setup.py Bump dependency on commonmark to >= 0.8.1 2019-03-18 20:52:17 -04:00
tox.ini Run against latest for lint/docs 2018-10-12 11:42:45 +02:00

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.

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.

Linking to headings in other files

For linking to headings in other files you can use the autosectionlabel sphinx feature, e.g.

# conf.py

extensions = [
    # Auto-generate section labels.
    'sphinx.ext.autosectionlabel',
]

# Prefix document path to section labels, otherwise autogenerated labels would look like 'heading'
# rather than 'path/to/file:heading'
autosectionlabel_prefix_document = True

You would use it like:

<!-- path/to/file_1.md -->

# Title

## My Subtitle
<!-- file_2.md -->

[My Subtitle][]

[My Subtitle]: <path/to/file_1:My Subtitle>

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_maxdepth: The max depth of the Auto Toc. Defaults to 1.
  • 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.
  • enable_label: enable the cross-referencing label feature.
  • url_resolver: a function that maps a existing relative position in the document to a http link
  • known_url_schemes: a list of url schemes to treat as URLs, schemes not in this list will be assumed to be Sphinx cross-references. Defaults to None, which means treat all URL schemes as URLs. Example: ['http', 'https', 'mailto']

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.