Debian Codegraph @

docs/src/markdown/extensions/critic.md

raw
1 ---
2 icon: lucide/pencil-line
3 ---
4 [:octicons-file-code-24:][_critic]{: .source-link }
5
6 # Critic
7
8 ## Overview
9
10 Critic is an extension that adds handling and support of [Critic Markup][critic-markup] which uses a special syntax to
11 represent edits to a Markdown document. This extension runs before all other extensions to parse the critic edits.
12
13 Critic allows you to automatically accept edits or reject the edits and render the output accordingly. It also allows
14 for visually displaying the changes in HTML output ([mileage may vary](#limitations-with-previewing-critic-markup)).
15
16 The Critic extension can be included in Python Markdown by using the following:
17
18 ```py3
19 import markdown
20 md = markdown.Markdown(extensions=['pymdownx.critic'])
21 ```
22
23 ## Usage
24
25 Critic Markup uses special markup to insert, delete, substitute, highlight, and comment.
26
27 To insert or remove text you can use `#!critic-markup {++insert me++}` and `#!critic-markup {--remove me--}`
28 respectively. You can also denote a substitution with `#!critic-markup {~~substitute this~>with this~~}`.
29
30 You can also highlight specific text with `#!critic-markup {==highlight me==}`. Or even comment, which is generally done
31 by highlighting text and following it with a comment: `#!critic-markup {==highlight me==}{>>Add a comment<<}`.
32
33 ```critic-markup title="Critic Markup Accept"
34 Here is some {--*incorrect*--} Markdown. I am adding this{++ here++}. Here is some more {--text
35 that I am removing--}text. And here is even more {++text that I
36 am ++}adding.{~~
37
38 ~> ~~}Paragraph was deleted and replaced with some spaces.{~~ ~>
39
40 ~~}Spaces were removed and a paragraph was added.
41
42 And here is a comment on {==some
43 text==}{>>This works quite well. I just wanted to comment on it.<<}. Substitutions {~~is~>are~~} great!
44
45 General block handling.
46
47 {--
48
49 * test remove
50 * test remove
51 * test remove
52 * test remove
53 * test remove
54
55 --}
56
57 {++
58
59 * test add
60 * test add
61 * test add
62 * test add
63 * test add
64
65 ++}
66 ```
67
68 /// html | div.result
69 ```md-render
70 ---
71 extensions:
72 - pymdownx.critic
73 extension_configs:
74 pymdownx.critic:
75 mode: accept
76 ---
77 Here is some {--*incorrect*--} Markdown. I am adding this{++ here++}. Here is some more {--text
78 that I am removing--}text. And here is even more {++text that I
79 am ++}adding.{~~
80
81 ~> ~~}Paragraph was deleted and replaced with some spaces.{~~ ~>
82
83 ~~}Spaces were removed and a paragraph was added.
84
85 And here is a comment on {==some
86 text==}{>>This works quite well. I just wanted to comment on it.<<}. Substitutions {~~is~>are~~} great!
87
88 General block handling.
89
90 {--
91
92 * test remove
93 * test remove
94 * test remove
95 * test remove
96 * test remove
97
98 --}
99
100 {++
101
102 * test add
103 * test add
104 * test add
105 * test add
106 * test add
107
108 ++}
109 ```
110 ///
111
112 When previewing, you can style them to stand out (see [CSS](#css) for more information):
113
114 ```critic-markup title="Critic Markup Preview"
115 Here is some {--*incorrect*--} Markdown. I am adding this{++ here++}. Here is some more {--text
116 that I am removing--}text. And here is even more {++text that I
117 am ++}adding.{~~
118
119 ~> ~~}Paragraph was deleted and replaced with some spaces.{~~ ~>
120
121 ~~}Spaces were removed and a paragraph was added.
122
123 And here is a comment on {==some
124 text==}{>>This works quite well. I just wanted to comment on it.<<}. Substitutions {~~is~>are~~} great!
125
126 General block handling.
127
128 {--
129
130 * test remove
131 * test remove
132 * test remove
133 * test remove
134 * test remove
135
136 --}
137
138 {++
139
140 * test add
141 * test add
142 * test add
143 * test add
144 * test add
145
146 ++}
147 ```
148
149 /// html | div.result
150 ```md-render
151 ---
152 extensions:
153 - pymdownx.critic
154 ---
155 Here is some {--*incorrect*--} Markdown. I am adding this{++ here++}. Here is some more {--text
156 that I am removing--}text. And here is even more {++text that I
157 am ++}adding.{~~
158
159 ~> ~~}Paragraph was deleted and replaced with some spaces.{~~ ~>
160
161 ~~}Spaces were removed and a paragraph was added.
162
163 And here is a comment on {==some
164 text==}{>>This works quite well. I just wanted to comment on it.<<}. Substitutions {~~is~>are~~} great!
165
166 General block handling.
167
168 {--
169
170 * test remove
171 * test remove
172 * test remove
173 * test remove
174 * test remove
175
176 --}
177
178 {++
179
180 * test add
181 * test add
182 * test add
183 * test add
184 * test add
185
186 ++}
187 ```
188 ///
189
190 ## Limitations with Previewing Critic Markup
191
192 Parsing CriticMarkup is very straight forward. If you need to reject critic marks or accept them, the Critic extension
193 will work quite well. But when trying to render the edits visually **and** trying to convert the document to HTML,
194 things can get ugly. I think this is the one unfortunate problem with CriticMarkup. The existence of the critic edits
195 can alter the actual source. Its a fantastic idea, but it should be understood that when using CriticMarkup beyond
196 inline or block paragraphs, there is a possibility that invalid HTML will be created for the preview (especially in
197 relation to lists or if breaking up Markdown syntax). I think Fletcher of [MultiMarkdown][multimarkdown-critic] said it
198 best.
199
200 /// quote
201 I view CriticMarkup as two things (in addition to the actual tools that implement these concepts):
202
203 1. A syntax for documenting editing notes and changes, and for collaborating amongst coauthors.
204
205 2. A means to display those notes/changes in the HTML output.
206
207 I believe that \#1 is a really great idea, and well implemented. \#2 is not so well implemented, largely due to the
208 "orthogonal" nature of CriticMarkup and the underlying Markdown syntax.
209 ///
210
211 The Critic extension does its best by employing a preprocessor to inject the critic tags before all other parsing and a
212 post-processor to clean up some of the weird side effects of the injection (only selected odd cases as others are more
213 difficult to fix). It injects some classes into the edit region's HTML output which allows for CSS styling. There is
214 probably a lot more post-processing that could be done to fix more issues, but there are no plans to enhance the view
215 mode any further than it already has been.
216
217 ## CSS
218
219 Critic renders the CriticMarkup with the following classes.
220
221 Classes | Description
222 --------- |------------
223 `critic` | This is applied to all critic edits.
224 `break` | This is applied to critic inserts or deletes that encompass **only** 2+ newlines.
225 `block` | Applied to critic HTML tags that are detected as surrounding a block region.
226 `comment` | A CriticMarkup comment.
227
228 /// settings | Basic CSS Setup
229
230 //// collapse-code
231 ```css
232 /* Critic Markup */
233 .markdown-body .critic {
234 font-family: inherit;
235 -webkit-border-radius: 3px;
236 -moz-border-radius: 3px;
237 border-radius: 3px;
238 border-style: solid;
239 border-width: 1px;
240 padding-top: 0.1em;
241 padding-bottom: 0.1em;
242 text-decoration: none;
243 }
244
245 .markdown-body .critic:before,
246 .markdown-body .critic:after {
247 content: '\00a0';
248 padding-top: 0.1em;
249 padding-bottom: 0.1em;
250 font-size: initial;
251 }
252
253 .markdown-body .block:before,
254 .markdown-body .block:after {
255 content: '';
256 }
257
258 .markdown-body mark.critic {
259 border-color: #ff8600;
260 background: #ffddaa;
261 }
262
263 .markdown-body ins.critic {
264 border-color: #00bb00;
265 background: #ddffdd;
266 }
267
268 .markdown-body del.critic {
269 border-color: #dd0000;
270 background: #ffdddd;
271 }
272
273 .markdown-body ins.break,
274 .markdown-body del.break {
275 font-size: 0;
276 border: none;
277 }
278
279 .markdown-body ins.break:before,
280 .markdown-body del.break:before {
281 content: '\00a0\b6\00a0';
282 -webkit-border-radius: 3px;
283 -moz-border-radius: 3px;
284 border-radius: 3px;
285 }
286
287 .markdown-body ins.after,
288 .markdown-body del.after {
289 content: '';
290 }
291
292 .markdown-body ins.break:before {
293 color: #00bb00;
294 border: 1px solid #00bb00;
295 background: #ddffdd;
296 }
297
298 .markdown-body del.break:before {
299 color: #bb0000;
300 border: 1px solid #bb0000;
301 background: #ffdddd;
302 }
303
304 .markdown-body span.critic {
305 background: #ddddff;
306 border: 0;
307 border-top: 1px solid #0000bb;
308 border-bottom: 1px solid #0000bb;
309 }
310
311 .markdown-body span.critic:before,
312 .markdown-body span.critic:after {
313 font-size: inherit;
314 background: #ddddff;
315 border: 1px solid #0000bb;
316 }
317
318 .markdown-body span.critic:before {
319 content: '\00a0\bb';
320 border-right: none;
321 -webkit-border-top-left-radius: 3px;
322 -moz-border-top-left-radius: 3px;
323 border-top-left-radius: 3px;
324 -webkit-border-bottom-left-radius: 3px;
325 -moz-border-bottom-left-radius: 3px;
326 border-bottom-left-radius: 3px;
327 }
328
329 .markdown-body span.critic:after {
330 content: '\ab\00a0';
331 border-left: none;
332 -webkit-border-top-right-radius: 3px;
333 -moz-border-top-right-radius: 3px;
334 border-top-right-radius: 3px;
335 -webkit-border-bottom-right-radius: 3px;
336 -moz-border-bottom-right-radius: 3px;
337 border-bottom-right-radius: 3px;
338 }
339
340 .markdown-body .block {
341 display: block;
342 padding: .02em;
343 }
344 ```
345 ////
346 ///
347
348 ## Options
349
350 Option | Type | Default | Description
351 --------- |------- | ----------- | -----------
352 `mode` | string | `#!py3 view` | `view` just parses the markup and displays it in its HTML equivalent rendering. `accept` strips out the critic markup and replaces them with the suggested changes. `reject` rejects all the suggestions and strips the critic markup out replacing it with the original.