Compatibility with rustdoc

This document compares the rustdoc markdown syntax and features with those supported by this extension via myst-parser. It also provides an explanation of the various myst-parser extensions that enable this compatibility.

Markdown syntax

myst-parser and Rust’s markdown both target the CommonMark specification. However, Rust provides some additional features that are not part of the CommonMark specification. Almost all of these syntax extensions are supported by myst-parser. The Markdown usage sections lists all the extensions required.

To make the docstrings work with both rustdoc and this tool, the following changes may be required to existing docstrings:

  1. Use double tilde (~~) only for strike-through.

  2. Use a backslash in front of literal text enclosed in brackets (\[foo] instead of [foo]) to prevent it from being rendered as broken link.

  3. Replace links that use Self::, self:: or super:: with the name of the type, value or macro. Links with crate:: in the target do not need to be updated.

  4. Use explicit text for the hyperlink when using namespaces and disambiguators, as in [`Foo`](struct@Foo) instead of [`struct@Foo`].

The sections below cover any differences in syntax and extensions required to make docstrings work with both Rust and Sphinx.

Attrs block

The attrs_block extension is used to separate the sections within docstrings from the sections of the table of contents. Essentially, the markdown sections in the docstrings are handled separately from the sections of the page. See the warning in https://myst-parser.readthedocs.io/en/latest/syntax/organising_content.html#document-structure for details.

Colon-fencing

The colon_fence extensions allows using colons (:::) for fencing instead of the usual back-ticks. This is used when generating the docs so they can be rendered properly in other markdown compatible tools. Removing this extension will cause issues with the generated documentation. See https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#code-fences-using-colons for details.

Strikethrough

Enable the strikethrough extension for myst-parser in conf.py and use ~~ for strikethrough in the docstrings. Rust supports a single ~, but myst-parser does not. See https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#strikethrough for details.

Footnotes

Both Rust and myst-parser use the same syntax for footnotes, so they should work as is. See https://myst-parser.readthedocs.io/en/latest/syntax/typography.html#footnotes for details.

Tables

Both Rust and myst-parser target the GitHub markdown table syntax. It should work out of the box.

Tasks List

Enable the tasklist extension for myst-parser in conf.py. The syntax is the same with this extension enabled. See https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#task-lists for details.

Smart punctuation

Enable the smartquotes and replacements extensions for myst-parser in conf.py. This will enable smart punctuation similar to Rust’s markdown and some more. See https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#typography for details.

Warning blocks and admonitions

Rust uses a separate div class for this as described here. To support a similar syntax for admonitions, enable the html_admonition extension for myst-parser in conf.py. See https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#html-admonitions for details. There are some additional features supported by myst-parser compared to Rust.

myst-parser supports Sphinx admonition directives as described at https://myst-parser.readthedocs.io/en/latest/syntax/admonitions.html, but they will not be rendered by rustdoc.

rustdoc features

Missing docs warning

This extension does not check for missing documentation when executed. It will list any items that it discovers, even when there are no docs for them. The warning may be supported in future.

#[doc] attributes

Crate level doc attributes are not supported. Most crate level doc attributes deal with the publication of the HTML and executing doctests. If any of these attributes are present, they are ignored when extracting the docs. The behavior of some HTML attributes may be achieved via Sphinx configuration options and extensions.

Item level doc attributes are not supported at present, but future versions may support some of them. This section will be updated as support for various attributes is implemented.

Re-exports

Re-exports are supported similar to rustdoc, with some differences in behavior. The tool does not currently recognize rustdoc attributes like inline, hidden and noinline. So, inlining is done purely based on whether the item will be documented in its original location or in a re-exported location. Documentation for the re-export is combined with the documentation of the original item, if the item is inlined.

Lints

The rustdoc-specific lints are not supported currently. There are no plans to support them at present. If this is required, please create an issue.