Debian Codegraph @

docs/src/markdown/extensions/tasklist.md

raw
1 ---
2 icon: lucide/list-todo
3 ---
4 [:octicons-file-code-24:][_tasklist]{: .source-link }
5
6 # Tasklist
7
8 ## Overview
9
10 The Tasklist extension adds GFM style task lists. They follow the same syntax as GFM. Simply start each list item with
11 a square bracket pair containing either a space (an unchecked item) or a `x` (a checked item).
12
13 /// note
14 All task lists in this documentation are generated with [`custom_checkbox`](#options) enabled.
15 ///
16
17 ```text title="Tasklist"
18 Task List
19
20 - [X] item 1
21 * [X] item A
22 * [ ] item B
23 more text
24 + [x] item a
25 + [ ] item b
26 + [x] item c
27 * [X] item C
28 - [ ] item 2
29 - [ ] item 3
30 ```
31
32 /// html | div.result
33 Task List
34
35 - [X] item 1
36 * [X] item A
37 * [ ] item B
38 more text
39 + [x] item a
40 + [ ] item b
41 + [x] item c
42 * [X] item C
43 - [ ] item 2
44 - [ ] item 3
45 ///
46
47 The Tasklist extension can be included in Python Markdown by using the following:
48
49 ```py3
50 import markdown
51 md = markdown.Markdown(extensions=['pymdownx.tasklist'])
52 ```
53
54 ## Styling with CSS
55
56 The HTML structure of a task list is found below:
57
58 /// tab | Default
59 This is the default output.
60
61 ```html
62 <ul class="task-list">
63 <li class="task-list-item">
64 <input type="checkbox" disabled="" checked="">
65 item 1
66 </li>
67 </ul>
68 ```
69 ///
70
71 /// tab | Custom
72 If `custom_checkbox` is enabled, the structure will be as follows:
73
74 ```html
75 <ul class="task-list">
76 <li class="task-list-item">
77 <label class="task-list-control">
78 <input type="checkbox" disabled checked="">
79 <span class="task-list-indicator"></span>
80 </label>
81 item 1
82 </li>
83 </ul>
84 ```
85 ///
86
87 /// tab | Clickable
88 If `clickable_checkbox` is enabled, user interaction will be allowed by removing the `disabled` attribute from the
89 `input` element. `clickable_checkbox` can be a applied to either the default or custom form.
90
91 ```html
92 <ul class="task-list">
93 <li class="task-list-item">
94 <label class="task-list-control">
95 <input type="checkbox" checked="">
96 <span class="task-list-indicator"></span>
97 </label>
98 item 1
99 </li>
100 </ul>
101 ```
102 ///
103
104 | Classes | Description |
105 | --------------------- | ------------------------------------------------------------------------------------------------------ |
106 | `task-list` | Attached to either the `ul` or `ol` tag and represents the entire list element. |
107 | `task-list-item` | This is attached the `li` tag and represents an item in the list. |
108 | `task-list-control` | This is attached to the `label` tag and represents the control object. |
109 | `task-list-indicator` | This is attached to the `span` directly following the input and is used to style the visual indicator. |
110
111 /// settings | CSS Setup
112
113 //// tab | Basic Tasklist
114 In order to style these we mainly remove the list type style and adjust the margins to align with normal list
115 styles.
116
117 ```css
118 .markdown-body .task-list-item {
119 list-style-type: none !important;
120 }
121
122 .markdown-body .task-list-item input[type="checkbox"] {
123 margin: 0 4px 0.25em -20px;
124 vertical-align: middle;
125 }
126 ```
127 ////
128
129 //// tab | Custom Tasklist
130
131 If custom check box icons are desired, custom styles can be used to give a unique look to the check marks.
132 Below is a very simple CSS example that creates a light gray square with rounded corners and displays a green
133 Unicode check mark when the control is checked. This can be adapted to use web fonts, images, etc.
134
135 ///// collapse-code
136 ```css
137 .markdown-body .task-list-item {
138 list-style-type: none !important;
139 }
140
141 .markdown-body .task-list-item input[type="checkbox"] {
142 margin: 0 4px 0.25em -20px;
143 vertical-align: middle;
144 }
145
146 .markdown-body .task-list-control {
147 display: inline; /* Ensure label is inline incase theme sets it to block.*/
148 }
149
150 .markdown-body .task-list-control {
151 position: relative;
152 display: inline-block;
153 color: #555;
154 cursor: pointer;
155 }
156
157 .markdown-body .task-list-control input[type="checkbox"] {
158 position: absolute;
159 opacity: 0;
160 z-index: -1; /* Put the input behind the label so it doesn't overlay text */
161 }
162
163 .markdown-body .task-list-indicator {
164 position: absolute;
165 top: -8px;
166 left: -18px;
167 display: block;
168 width: 14px;
169 height: 14px;
170 color: #eee;
171 background-color: #eee;
172 border-radius: .25rem;
173 }
174
175 .markdown-body .task-list-control input[type="checkbox"]:checked + .task-list-indicator::before {
176 display: block;
177 margin-top: -4px;
178 margin-left: 2px;
179 font-size: 16px;
180 line-height: 1;
181 content: "✔";
182 color: #1EBB52;
183 }
184 ```
185 /////
186 ////
187 ///
188
189 ## Options
190
191 Option | Type | Default | Description
192 -------------------- | ---- | ------------ | ------------
193 `custom_checkbox` | bool | `#!py3 False` | Generate task lists in such a way as to allow for styling the check box with CSS.
194 `clickable_checkbox` | bool | `#!py3 False` | Enable user to interact with checkboxes.