Debian Codegraph @

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

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