key3: |
```{image} img/fun-fish.png
:alt: fishy
:width: 200px
```
key4: example
---
(syntax/optional)=
# Optional MyST Syntaxes
MyST-Parser is highly configurable, utilising the inherent "plugability" of the [markdown-it-py](markdown_it:index) parser.
The following syntaxes are optional (disabled by default) and can be enabled *via* the sphinx `conf.py` (see also [](intro/config-options)).
Their goal is generally to add more *Markdown friendly* syntaxes; often enabling and rendering [markdown-it-py plugins](markdown_it:md/plugins) that extend the [CommonMark specification](https://commonmark.org/).
To enable all the syntaxes explained below:
```python
myst_enable_extensions = [
"amsmath",
"colon_fence",
"deflist",
"dollarmath",
"html_admonition",
"html_image",
"linkify",
"replacements",
"smartquotes",
"substitution"
]
```
:::{important}
`myst_enable_extensions` replaces previous configuration options:
`admonition_enable`, `figure_enable`, `dmath_enable`, `amsmath_enable`, `deflist_enable`, `html_img_enable`
:::
(syntax/typography)=
## Typography
Adding `"smartquotes"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)) will automatically convert standard quotations to their opening/closing variants:
- `'single quotes'`: 'single quotes'
- `"double quotes"`: "double quotes"
Adding `"replacements"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)) will automatically convert some common typographic texts
text | converted
----- | ----------
``(c)``, ``(C)`` | (c)
``(tm)``, ``(TM)`` | (tm)
``(r)``, ``(R)`` | (r)
``(p)``, ``(P)`` | (p)
``+-`` | +-
``...`` | ...
``?....`` | ?....
``!....`` | !....
``????????`` | ????????
``!!!!!`` | !!!!!
``,,,`` | ,,,
``--`` | --
``---`` | ---
(syntax/linkify)=
## Linkify
Adding `"linkify"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)) will automatically identify "bare" web URLs and add hyperlinks:
`www.example.com` -> www.example.com
:::{important}
This extension requires that [linkify-it-py](https://github.com/tsutsu3/linkify-it-py) is installed.
Either directly; `pip install linkify-it-py` or *via* `pip install myst-parser[linkify]`.
:::
(syntax/substitutions)=
## Substitutions (with Jinja2)
Adding `"substitution"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)) will allow you to add substitutions, added in either the `conf.py` using `myst_substitutions`:
```python
myst_substitutions = {
"key1": "I'm a **substitution**"
}
```
or at the top of the file, in the front-matter section (see [this section](syntax/frontmatter)):
````yaml
---
substitutions:
key1: "I'm a **substitution**"
key2: |
```{note}
{{ key1 }}
```
key3: |
```{image} img/fun-fish.png
:alt: fishy
:width: 200px
```
key4: example
---
````
:::{important}
Keys in the front-matter will override ones in the `conf.py`.
:::
You can use these substitutions inline or as blocks, and you can even nest substitutions in other substitutions (but circular references are prohibited):
:::{tabbed} Markdown Input
```md
Inline: {{ key1 }}
Block level:
{{ key2 }}
| col1 | col2 |
| -------- | -------- |
| {{key2}} | {{key3}} |
```
:::
:::{tabbed} Rendered Output
Inline: {{ key1 }}
Block level:
{{ key2 }}
| col1 | col2 |
| -------- | -------- |
| {{key2}} | {{key3}} |
:::
:::{important}
Substitutions will only be assessed where you would normally use Markdown, e.g. not in code blocks:
````
```
{{ key1 }}
```
````
```
{{ key1 }}
```
One should also be wary of using unsuitable directives for inline substitutions.
This may lead to unexpected outcomes.
:::
Substitution references are assessed as [Jinja2 expressions](http://jinja.palletsprojects.com) which can use [filters](https://jinja.palletsprojects.com/en/2.11.x/templates/#list-of-builtin-filters), and also contains the [Sphinx Environment](https://www.sphinx-doc.org/en/master/extdev/envapi.html) in the context (as `env`).
Therefore you can do things like:
```md
{{ env.docname | upper }}
{{ "a" + "b" }}
```
{{ env.docname | upper }}
{{ "a" + "b" }}
You can also change the delimiter if necessary, for example setting in the `conf.py`:
```python
myst_sub_delimiters = ["|", "|"]
```
Will parse: `|| "a" + "b" ||`.
This should be changed with care though, so as not to affect other syntaxes.
The exact logic for handling substitutions is:
1. Combine global substitutions (specified in `conf.py`) with front-matter substitutions, to create a variable context (front-matter takes priority)
2. Add the sphinx `env` to the variable context
3. Create the string content to render using Jinja2 (passing it the variable context)
4. If the substitution is inline and not a directive, render ignoring block syntaxes (like lists or block-quotes), otherwise render with all syntax rules.
### Substitutions and URLs
Substitutions cannot be directly used in URLs, such as `[a link](https://{{key4}}.com)` or `
This was created from:
```md
Term *with Markdown*
: Definition [with reference](syntax/definition-lists)
A second paragraph
Term 2
~ Definition 2a
~ Definition 2b
Term 3
: A code block
: > A quote
: A final definition, that can even include images:
```
(syntax/images)=
## Images
MyST provides a few different syntaxes for including images in your documentation, as explained below.
The first is the standard Markdown syntax:
```md

```

This will correctly copy the image to the build folder and will render it in all output formats (HTML, TeX, etc).
However, it is limited in the configuration that can be applied, for example setting a width.
As discussed [above](syntax/directives), MyST allow for directives to be used such as `image` and `figure` (see {ref}`the sphinx documentation
```
Allowed attributes are equivalent to the `image` directive: src, alt, class, width, height and name.
Any other attributes will be dropped.
HTML image can also be used inline!
I'm an inline image:
(syntax/figures)=
## Markdown Figures
By adding `"colon_fence"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)),
we can combine the above two extended syntaxes,
to create a fully Markdown compliant version of the `figure` directive named `figure-md`.
:::{important}
`myst_figure_enable` with the `figure` directive is deprecated and replaced by `myst_enable_extensions = ["colon_fence"]` and `figure-md`.
:::
The figure block must contain **only** two components; an image, in either Markdown or HTML syntax, and a single paragraph for the caption.
The title is optional and taken as the reference target of the figure:
```md
:::{figure-md} fig-target
:class: myclass
This is a caption in **Markdown**
:::
```
:::{figure-md} fig-target
:class: myclass
This is a caption in **Markdown**
:::
As we see here, the target we set can be referenced:
```md
[Go to the fish!](fig-target)
```
[Go to the fish!](fig-target)
(syntax/html-admonition)=
## HTML Admonitions
By adding `"html_admonition"` to `myst_enable_extensions` (in the sphinx `conf.py` [configuration file](https://www.sphinx-doc.org/en/master/usage/configuration.html)),
you can enable parsing of ``, then this will be set as the admonition title. All internal text (and the title) will be parsed as MyST-Markdown and all classes and an optional name will be passed to the admonition: ```html
This is the **title**
This is the *content*`: ```html
Paragraph 1
Paragraph 2
Paragraph 1
Paragraph 2
Some **content**
Paragraph 1
Paragraph 2
Some **content**
Paragraph 1
Paragraph 2