We propose a simplified syntax to allow arugments for all named admonitions. The syntax allows an argument for any title of a named admonition like {tip}
, to allow users to easily set the color and icon of an admonition while also having a custom title. The proposed syntax is:
The original RST directives for named admonitions attention, caution, danger, error, hint, important, note, tip, and warning are designed for a single line, and allow you have the entire named admonition in a compact form.
Any text immediately following the directive indicator (on the same line and/or indented on following lines) is interpreted as a directive block and is parsed for normal body elements.
- See docutils
For example, the {note}
directive argument will be treated as body text:
There is a general admonition directive that does support the inclusion of custom titles, but lacks the unifying kind & style information.
This syntax has been adopted directly in MyST, and has been demonstrated to confuse our users[1] who expect to be able to easily edit the admonition title without changing the directive kind.
Currently the only way to edit the title of an admonition, while still picking up on a specific style, color and icon is to use the base {admonition}
directive and specify a class attribute.
We propose a simplified way to create styled admonitions with titles, where the argument is always the title of the admonition.
This syntax presents a clear mapping of text content to parts of the rendered admonition: (1) the icon, style & semantics (i.e. {note}
); (2) the title as an argument; and (3) the body of the admonition in the fence. It also has the advantage of not requiring the user to know the word admonition
, which is not commonly used outside of Sphinx and Docutils[2].
The argument would be optional, with a fallback to the default title (e.g. "Note" in this case).
The current behavoiur around admonitions with classes should continue to be supported, so the following examples are the suggested way to document admonitions with titles rather than the only way that they can be written.
Before:
After:
The user experience is enhanced as the new syntax provides a direct one-to-one mapping between the markup text and the rendered outcome.
This MEP also reduces the complexity of the overall MyST syntax as it moves named admonitions towards a more general usage of arguments, with less conditional logic in parsing.
This will deviate from the sphinx/docutils
specification that defines reStructuredText which uses any supplied elements to the directive as body text.
If this MEP is approved the following syntax:
would no longer render as:
but instead would render as:
We propose an automated code modification that can be run on existing projects to target this upgrade, for example:
This codemod will target named admonitions in markdown and Jupyter Notebooks to insert a new line and preserve the intended behaviour.