Debian Codegraph @

docs/src/markdown/extensions/blocks/plugins/admonition.md

raw
1 ---
2 icon: lucide/sticky-note
3 ---
4
5 [:octicons-file-code-24:][_admonition_block]{: .source-link }
6
7 # Admonition
8
9 /// danger | Using `pymdownx.blocks.admonition` with `admonition`
10 The new `pymdownx.blocks.admonition` extension is meant to replace `admonition`, they are not meant to be used together.
11 Their output is identical making it easy to transition by simply swapping out the syntax, but using them both together
12 can cause issues as they both generate the same output and confuse each other.
13
14 If you are switching from `admonition` to `pymdownx.blocks.admonition`, ensure you disable `admonition` to avoid issues.
15 ///
16
17 /// tip
18 If an approach like Obsidian is preferred, 10.20 adds support via the [Quotes extension](../../quotes.md) for Obsidian
19 style callouts.
20 ///
21
22 ## Overview
23
24 Admonition blocks are an alternative to using Python Markdown's [built-in extension][admonition]. The output is
25 identical, but they use the new generic block syntax.
26
27 By default, the meta-plugin is registered when `pymdownx.blocks` is registered, but if you were customizing which
28 meta-plugins get loaded, you can do so by doing the following:
29
30 ```py3
31 import markdown
32 md = markdown.Markdown(extensions=['pymdownx.blocks.admonition'])
33 ```
34
35 ## Usage
36
37 Admonitions can be specified using the generic block syntax and the name `admonition`. A title can be specified in
38 the header.
39
40 ```text title="Admonition"
41 /// admonition | Some title
42 Some content
43 ///
44 ```
45
46 /// html | div.result
47 //// admonition | Some title
48 Some content
49 ////
50 ///
51
52 If desired, you can attach a class to an admonition using the option `type`. If type is set, a class with that name will
53 be added, and if there is no title, the class name will be used as the title: `note` -> `Note`.
54
55 ```text title="Admonition"
56 /// admonition | Some title
57 type: warning
58
59 Some content
60 ///
61 ```
62
63 /// html | div.result
64 //// admonition | Some title
65 type: warning
66
67 Some content
68 ////
69 ///
70
71
72 As a shortcut, Admonitions registers a number of admonition blocks that attach common classes: note, attention, caution,
73 danger, error, tip, hint, warning.
74
75 These require you to use their special name. When using these, you do not need to attach class `note`, `attention`, etc.
76 as they are already done for you.
77
78 ```text title="Note"
79 /// note | Some title
80 Some content
81 ///
82 ```
83
84 /// html | div.result
85 //// note | Some title
86 Some content
87 ////
88 ///
89
90 These default types can actually be overridden or extended by using the global `types` option. Keep in mind that names
91 cannot conflict with other registered Block plugin names you are using.
92
93 ```py3
94 import markdown
95 from pymdownx.blocks.admonition import Admonition
96
97 md = markdown.Markdown(
98 extensions=['pymdownx.blocks.admonition'],
99 extension_configs={
100 'pymdownx.blocks.admonition': {
101 'types': ['note', 'warning', 'some-custom-type']
102 }
103 }
104 )
105 ```
106
107 And then you can use your defined types:
108
109 ```
110 /// some-custom-type | Some title
111 Some content
112 ///
113 ```
114
115 If further control is desired, you can optionally configure a custom block with a name that differs from the actual
116 attached class. You can also configure a default title that is not derived from the attached class.
117
118 ```py3
119 import markdown
120 from pymdownx.blocks.admonition import Admonition
121
122 md = markdown.Markdown(
123 extensions=['pymdownx.blocks.admonition'],
124 extension_configs={
125 'pymdownx.blocks.admonition": {
126 'types': [{'name': 'some-custom-type', 'class': 'custom', 'title': 'My Default title'}]
127 }
128 }
129 )
130 ```
131
132 Now when using:
133
134 ```
135 /// some-custom-type
136 content
137 ///
138 ```
139
140 It would be the same as using:
141
142 ```
143 /// admonition | My Default Title
144 type: custom
145
146 content
147 ///
148 ```
149
150 As with all block plugins, you can always add new classes IDs or other attributes via the `attributes` option.
151
152 ```
153 /// note | Some title
154 attrs: {class: class-name: id: id-name}
155
156 Some content
157 ///
158 ```
159
160 /// new | New 10.5
161 Specifying custom blocks with specific classes and default titles is new in 10.5.
162 ///
163
164 ## Global Options
165
166 Options | Type | Descriptions
167 ------- | ---------- | ------------
168 `types` | \[string\] | Specify new plugin subclasses to register for specific admonition types.
169
170 ## Per Block Options
171
172 Options | Type | Descriptions
173 ------------ | ---------- | ------------
174 `type` | string | A class name to apply as the admonition type.
175 `attrs` | dictionary | A dictionary that defines attributes for the outer, wrapper element.