Debian Codegraph @

docs/src/markdown/extensions/progressbar.md

raw
1 ---
2 icon: lucide/percent
3 ---
4 [:octicons-file-code-24:][_progressbar]{: .source-link }
5
6 # ProgressBar
7
8 ## Overview
9
10 ProgressBar is an extension that adds support for progress/status bars. It can take percentages or fractions, and it
11 can optionally generate classes for percentages at specific value levels. It also works with Python Markdown's built
12 in `attr_list` extension.
13
14 The basic syntax for progress bars is: `[= <percentage or fraction> "optional single or double quoted title"]`. The
15 opening `[` can be followed by one or more `=` characters. After the `=` char(s) the percentage is specified as either
16 a fraction or percentage and can optionally be followed by a title surrounded in either double quotes or single
17 quotes.
18
19 ```text title="Progress Bars"
20 [=0% "0%"]
21 [=5% "5%"]
22 [=25% "25%"]
23 [=45% "45%"]
24 [=65% "65%"]
25 [=85% "85%"]
26 [=100% "100%"]
27 ```
28
29 /// html | div.result
30 [=0% "0%"]
31 [=5% "5%"]
32 [=25% "25%"]
33 [=45% "45%"]
34 [=65% "65%"]
35 [=85% "85%"]
36 [=100% "100%"]
37 ///
38
39 Though progress bars are rendered as block items, it accepts `attr_list`'s inline format.
40 `markdown.extensions.attr_list` must be enabled for the following to work.
41
42 ```text title="Progress Bars with Attributes"
43 [=85% "85%"]{: .candystripe}
44 [=100% "100%"]{: .candystripe .candystripe-animate}
45
46 [=0%]{: .thin}
47 [=5%]{: .thin}
48 [=25%]{: .thin}
49 [=45%]{: .thin}
50 [=65%]{: .thin}
51 [=85%]{: .thin}
52 [=100%]{: .thin}
53 ```
54
55 /// html | div.result
56 [=85% "85%"]{: .candystripe}
57 [=100% "100%"]{: .candystripe .candystripe-animate}
58
59 [=0%]{: .thin}
60 [=5%]{: .thin}
61 [=25%]{: .thin}
62 [=45%]{: .thin}
63 [=65%]{: .thin}
64 [=85%]{: .thin}
65 [=100%]{: .thin}
66 ///
67
68 The ProgressBar extension can be included in Python Markdown by using the following:
69
70 ```py3
71 import markdown
72 md = markdown.Markdown(extensions=['pymdownx.progressbar'])
73 ```
74
75 ## Styling with CSS
76
77 The general HTML structure of the progress bar is as follows:
78
79 ```html
80 <div class="progress progress-100plus">
81 <div class="progress-bar" style="width:100.00%">
82 <p class="progress-label">100%</p>
83 </div>
84 </div>
85 ```
86
87 Classes | Description
88 ------------------------ |------------
89 `progress` | This is attached to the outer `div` container of the progress bar.
90 `progress-bar` | This is attached to the inner `div` whose width is adjusted to give the visual appearance of a bar at the desired percentage.
91 `progress-label` | This is attached to the `p` element that will contain the desired label.
92 `progress-<integer>plus` | This is an optional class that indicates the percentage of the progress bar by increments defined by `progress_increment`.
93
94 /// settings | CSS Setup
95
96 You are able to style your progress bars as fancy or plain as you want. Below is just a basic example. Depending
97 on existing styles in your page, it may or may not require tweaking.
98
99 //// tab | Preview
100 ![Progress bar](../images/progress.png)
101 ////
102
103 //// tab | HTML
104 ```html
105 <h1>Goals</h1>
106 <hr />
107 <p>
108 <div class="progress progress-20plus">
109 <div class="progress-bar" style="width:25.00%">
110 <p class="progress-label">25%</p>
111 </div>
112 </div>
113 </p>
114 ```
115 ////
116
117 //// tab | CSS
118 ///// collapse-code
119 ```css
120 .progress-label {
121 position: absolute;
122 text-align: center;
123 font-weight: 700;
124 width: 100%;
125 margin: 0;
126 line-height: 1.2rem;
127 white-space: nowrap;
128 overflow: hidden;
129 }
130
131 .progress-bar {
132 height: 1.2rem;
133 float: left;
134 background-color: #2979ff;
135 }
136
137 .progress {
138 display: block;
139 width: 100%;
140 margin: 0.5rem 0;
141 height: 1.2rem;
142 background-color: #eeeeee;
143 position: relative;
144 }
145
146 .progress.thin {
147 margin-top: 0.9rem;
148 height: 0.4rem;
149 }
150
151 .progress.thin .progress-label {
152 margin-top: -0.4rem;
153 }
154
155 .progress.thin .progress-bar {
156 height: 0.4rem;
157 }
158
159 .progress-100plus .progress-bar {
160 background-color: #00e676;
161 }
162
163 .progress-80plus .progress-bar {
164 background-color: #fbc02d;
165 }
166
167 .progress-60plus .progress-bar {
168 background-color: #ff9100;
169 }
170
171 .progress-40plus .progress-bar {
172 background-color: #ff5252;
173 }
174
175 .progress-20plus .progress-bar {
176 background-color: #ff1744;
177 }
178
179 .progress-0plus .progress-bar {
180 background-color: #f50057;
181 }
182 ```
183 /////
184 ////
185 ///
186
187 ## Options
188
189 Option | Type | Default | Description
190 -------------------- | ------- | ------------ |------------
191 `level_class` | bool | `#!py3 True` | Enables or disables the level class feature. The level class feature adds level classes in increments defined by `progress_increment`.
192 `add_classes` | string | `#!py3 ''` | This option accepts a string of classes separated by spaces.
193 `progress_increment` | integer | `#!py3 20` | Defines the increment at which the `level_class` classes are generated at.