1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
---
icon: material/plus-circle
---
# Annotations
One of the flagship features of Material for MkDocs is the ability to inject
annotations – little markers that can be added almost anywhere in a document
and expand a tooltip containing arbitrary Markdown on click or keyboard focus.
## Configuration
This configuration allows to add annotations to all inline- and block-level
elements, as well as code blocks, and nest annotations inside each other. Add
the following lines to `mkdocs.yml`:
``` yaml
markdown_extensions:
- attr_list
- md_in_html
- pymdownx.superfences
```
See additional configuration options:
- [Attribute Lists]
- [Markdown in HTML]
- [SuperFences]
[Attribute Lists]: ../setup/extensions/python-markdown.md#attribute-lists
[Markdown in HTML]: ../setup/extensions/python-markdown.md#markdown-in-html
[SuperFences]: ../setup/extensions/python-markdown-extensions.md#superfences
### Annotation icons
<!-- md:version 9.2.0 -->
The annotation icon can be changed to any icon bundled with the theme, or even
a [custom icon], e.g. to material/arrow-right-circle:. Simply add the following
lines to `mkdocs.yml`:
``` yaml
theme:
icon:
annotation: material/arrow-right-circle # (1)!
```
1. Enter a few keywords to find the perfect icon using our [icon search] and
click on the shortcode to copy it to your clipboard:
<div class="mdx-iconsearch" data-mdx-component="iconsearch">
<input class="md-input md-input--stretch mdx-iconsearch__input" placeholder="Search icon" data-mdx-component="iconsearch-query" value="material circle" />
<div class="mdx-iconsearch-result" data-mdx-component="iconsearch-result" data-mdx-mode="file">
<div class="mdx-iconsearch-result__meta"></div>
<ol class="mdx-iconsearch-result__list"></ol>
</div>
</div>
Some popular choices:
- :material-plus-circle: - `material/plus-circle`
- :material-circle-medium: - `material/circle-medium`
- :material-record-circle: - `material/record-circle`
- :material-arrow-right-circle: - `material/arrow-right-circle`
- :material-arrow-right-circle-outline: - `material/arrow-right-circle-outline`
- :material-chevron-right-circle: - `material/chevron-right-circle`
- :material-star-four-points-circle: - `material/star-four-points-circle`
- :material-plus-circle-outline: - `material/plus-circle-outline`
[custom icon]: ../setup/changing-the-logo-and-icons.md#additional-icons
[icon search]: icons-emojis.md#search
## Usage
### Using annotations
<!-- md:version 9.2.0 -->
<!-- md:flag experimental -->
Annotations consist of two parts: a marker, which can be placed anywhere in
a block marked with the `annotate` class, and content located in a list below
the block containing the marker:
``` markdown title="Text with annotations"
Lorem ipsum dolor sit amet, (1) consectetur adipiscing elit.
{ .annotate }
1. :man_raising_hand: I'm an annotation! I can contain `code`, __formatted
text__, images, ... basically anything that can be expressed in Markdown.
```
<div class="result" markdown>
Lorem ipsum dolor sit amet, (1) consectetur adipiscing elit.
{ .annotate }
1. :man_raising_hand: I'm an annotation! I can contain `code`, __formatted
text__, images, ... basically anything that can be written in Markdown.
</div>
Note that the `annotate` class must only be added to the outermost block. All
nested elements can use the same list to define annotations, except when
annotations are nested themselves.
#### in annotations
When [SuperFences] is enabled, annotations can be nested inside annotations by
adding the `annotate` class to the list item hosting the annotation content,
repeating the process:
``` markdown title="Text with nested annotations"
Lorem ipsum dolor sit amet, (1) consectetur adipiscing elit.
{ .annotate }
1. :man_raising_hand: I'm an annotation! (1)
{ .annotate }
1. :woman_raising_hand: I'm an annotation as well!
```
<div class="result" markdown>
Lorem ipsum dolor sit amet, (1) consectetur adipiscing elit.
{ .annotate }
1. :man_raising_hand: I'm an annotation! (1)
{ .annotate style="margin-bottom: 0" }
1. :woman_raising_hand: I'm an annotation as well!
</div>
#### in admonitions
The titles and bodies of [admonitions] can also host annotations by adding the
`annotate` modifier after the type qualifier, which is similar to how
[inline blocks] work:
``` markdown title="Admonition with annotations"
!!! note annotate "Phasellus posuere in sem ut cursus (1)"
Lorem ipsum dolor sit amet, (2) consectetur adipiscing elit. Nulla et
euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo
purus auctor massa, nec semper lorem quam in massa.
1. :man_raising_hand: I'm an annotation!
2. :woman_raising_hand: I'm an annotation as well!
```
<div class="result" markdown>
!!! note annotate "Phasellus posuere in sem ut cursus (1)"
Lorem ipsum dolor sit amet, (2) consectetur adipiscing elit. Nulla et
euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo
purus auctor massa, nec semper lorem quam in massa.
1. :man_raising_hand: I'm an annotation!
2. :woman_raising_hand: I'm an annotation as well!
</div>
[admonitions]: admonitions.md
[inline blocks]: admonitions.md#inline-blocks
#### in content tabs
Content tabs can host annotations by adding the `annotate` class to the block
of a dedicated content tab (and not to the container, which is not supported):
``` markdown title="Content tabs with annotations"
=== "Tab 1"
Lorem ipsum dolor sit amet, (1) consectetur adipiscing elit.
{ .annotate }
1. :man_raising_hand: I'm an annotation!
=== "Tab 2"
Phasellus posuere in sem ut cursus (1)
{ .annotate }
1. :woman_raising_hand: I'm an annotation as well!
```
<div class="result" markdown>
=== "Tab 1"
Lorem ipsum dolor sit amet, (1) consectetur adipiscing elit.
{ .annotate }
1. :man_raising_hand: I'm an annotation!
=== "Tab 2"
Phasellus posuere in sem ut cursus (1)
{ .annotate }
1. :woman_raising_hand: I'm an annotation as well!
</div>
#### in everything else
The [Attribute Lists] extension is the key ingredient for adding annotations to
most elements, but it has some [limitations]. However, it's always possible to
leverage the [Markdown in HTML] extension to wrap arbitrary elements with a
`div` with the `annotate` class:
```` html title="HTML with annotations"
<div class="annotate" markdown>
> Lorem ipsum dolor sit amet, (1) consectetur adipiscing elit.
</div>
1. :man_raising_hand: I'm an annotation!
````
<div class="result" markdown>
<div class="annotate" markdown>
> Lorem ipsum dolor sit amet, (1) consectetur adipiscing elit.
</div>
1. :man_raising_hand: I'm an annotation!
</div>
With this trick, annotations can also be added to blockquotes, lists, and many
other elements that are not supported by the [Attribute Lists] extension.
Furthermore, note that [code blocks follow different semantics].
!!! warning "Known limitations"
Please note that annotations currently don't work in [data tables] as
reported in #3453, as data tables are scrollable elements and positioning
is very tricky to get right. This might be fixed in the future.
[limitations]: https://python-markdown.github.io/extensions/attr_list/#limitations
[code blocks follow different semantics]: code-blocks.md#adding-annotations
[data tables]: data-tables.md
|