satteri-pulldown-cmark 0.3.6

A fork of the pulldown-cmark crate with MDX extensions, used in the satteri project.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
Run this with `cargo test --features gen-tests suite::math`.

# Math

Mathematical expressions following the remark-math convention.
Inline math uses `$...$`, display math uses `$$` fences on separate lines.

## Inline math

Basic inline math:

```````````````````````````````` example
$x=y$
.
<p><code class="language-math math-inline">x=y</code></p>
````````````````````````````````

Inline math with LaTeX:

```````````````````````````````` example
$\sqrt{3x-1}+(1+x)^2$
.
<p><code class="language-math math-inline">\sqrt{3x-1}+(1+x)^2</code></p>
````````````````````````````````

Inline math without surrounding whitespace:

```````````````````````````````` example
foo$1+1 = 2$bar
.
<p>foo<code class="language-math math-inline">1+1 = 2</code>bar</p>
````````````````````````````````

Multiple inline math expressions:

```````````````````````````````` example
$a$ and $b$
.
<p><code class="language-math math-inline">a</code> and <code class="language-math math-inline">b</code></p>
````````````````````````````````

Adjacent inline math:

```````````````````````````````` example
$a$$b$
.
<p><code class="language-math math-inline">a$$b</code></p>
````````````````````````````````

Multiline inline math:

```````````````````````````````` example
$5x + 2 =
17$
.
<p><code class="language-math math-inline">5x + 2 =
17</code></p>
````````````````````````````````

Double dollar signs inline produce inline math:

```````````````````````````````` example
$$\alpha$$
.
<p><code class="language-math math-inline">\alpha</code></p>
````````````````````````````````

Math content ignores HTML:

```````````````````````````````` example
$a<b>c</b>$
.
<p><code class="language-math math-inline">a&#x3C;b>c&#x3C;/b></code></p>
````````````````````````````````

Math content ignores backticks:

```````````````````````````````` example
$not `code`$
.
<p><code class="language-math math-inline">not `code`</code></p>
````````````````````````````````

Math content ignores markdown links:

```````````````````````````````` example
$![not an](/image)$
.
<p><code class="language-math math-inline">![not an](/image)</code></p>
````````````````````````````````

Math content ignores autolinks:

```````````````````````````````` example
$<https://not.a.link/>$
.
<p><code class="language-math math-inline">&#x3C;https://not.a.link/></code></p>
````````````````````````````````

Math content ignores entities:

```````````````````````````````` example
$&alpha;$
.
<p><code class="language-math math-inline">&#x26;alpha;</code></p>
````````````````````````````````

Inline math cannot start with whitespace:

```````````````````````````````` example
$ y=x$
.
<p><code class="language-math math-inline"> y=x</code></p>
````````````````````````````````

Inline math cannot end with whitespace:

```````````````````````````````` example
$y=x $
.
<p><code class="language-math math-inline">y=x </code></p>
````````````````````````````````

Unclosed dollar signs are plain text:

```````````````````````````````` example
Hello $world.
.
<p>Hello $world.</p>
````````````````````````````````

Dollar at end of line:

```````````````````````````````` example
Dollar at end of line$
.
<p>Dollar at end of line$</p>
````````````````````````````````

Escaped dollar in math:

```````````````````````````````` example
$\$$
.
<p>$$$</p>
````````````````````````````````

Backslashes in math:

```````````````````````````````` example
$\{a\,b\}$
.
<p><code class="language-math math-inline">\{a\,b\}</code></p>
````````````````````````````````

Inline math in emphasis:

```````````````````````````````` example
_$a$ equals $b$_
.
<p><em><code class="language-math math-inline">a</code> equals <code class="language-math math-inline">b</code></em></p>
````````````````````````````````

Inline math in strong:

```````````````````````````````` example
**$a$ equals $b$**
.
<p><strong><code class="language-math math-inline">a</code> equals <code class="language-math math-inline">b</code></strong></p>
````````````````````````````````

Inline math preceded by text:

```````````````````````````````` example
a$x$
.
<p>a<code class="language-math math-inline">x</code></p>
````````````````````````````````

Math as only item on a line:

```````````````````````````````` example
$x=y$
.
<p><code class="language-math math-inline">x=y</code></p>
````````````````````````````````

Text following inline math:

```````````````````````````````` example
$n$-th order
.
<p><code class="language-math math-inline">n</code>-th order</p>
````````````````````````````````

Math with angle brackets:

```````````````````````````````` example
$a <b > c$
.
<p><code class="language-math math-inline">a &#x3C;b > c</code></p>
````````````````````````````````

Math with markdown-like content:

```````````````````````````````` example
$[(a+b)c](d+e)$
.
<p><code class="language-math math-inline">[(a+b)c](d+e)</code></p>
````````````````````````````````

Math with underscores:

```````````````````````````````` example
${a}_b c_{d}$
.
<p><code class="language-math math-inline">{a}_b c_{d}</code></p>
````````````````````````````````

Currency amounts are not math:

```````````````````````````````` example
Thus, $20,000 and USD$30,000 won't parse
.
<p>Thus, <code class="language-math math-inline">20,000 and USD</code>30,000 won't parse</p>
````````````````````````````````

Whitespace after opening dollar prevents math:

```````````````````````````````` example
It is 2$ for a can of soda, not 1$.
.
<p>It is 2<code class="language-math math-inline"> for a can of soda, not 1</code>.</p>
````````````````````````````````

Whitespace before closing dollar prevents math:

```````````````````````````````` example
I'll give $20 today, if you give me more $ tomorrow.
.
<p>I'll give <code class="language-math math-inline">20 today, if you give me more </code> tomorrow.</p>
````````````````````````````````

Escaped dollars inside math:

```````````````````````````````` example
Money adds: $\$X + \$Y = \$Z$.
.
<p>Money adds: <code class="language-math math-inline">\</code>X + $Y = $Z$.</p>
````````````````````````````````

Hard breaks not recognized in math:

```````````````````````````````` example
$not a\
hard break  
either$
.
<p><code class="language-math math-inline">not a\
hard break  
either</code></p>
````````````````````````````````

Inline math with escaped closing dollar:

```````````````````````````````` example
$\alpha\$
.
<p><code class="language-math math-inline">\alpha\</code></p>
````````````````````````````````

## Precedence and greedy parsing

Inline math vs code span — math first:

```````````````````````````````` example
$Inline `first$ then` code
.
<p><code class="language-math math-inline">Inline `first</code> then` code</p>
````````````````````````````````

Inline math vs code span — code first:

```````````````````````````````` example
`Code $first` then$ inline
.
<p><code>Code $first</code> then$ inline</p>
````````````````````````````````

Display math vs code span — math first:

```````````````````````````````` example
$$ Display `first $$ then` code
.
<p><code class="language-math math-inline">Display `first</code> then` code</p>
````````````````````````````````

Display math vs code span — code first:

```````````````````````````````` example
`Code $$ first` then $$ display
.
<p><code>Code $$ first</code> then $$ display</p>
````````````````````````````````

Empty inline math not allowed:

```````````````````````````````` example
Oops empty $$ expression.
.
<p>Oops empty $$ expression.</p>
````````````````````````````````

Greedy left-to-right dollar parsing:

```````````````````````````````` example
$x$$$$$$$y$$
.
<p>$x$$$$$$$y$$</p>
````````````````````````````````

Greedy left-to-right dollar parsing 2:

```````````````````````````````` example
$x$$$$$$y$$
.
<p>$x$$$$$$y$$</p>
````````````````````````````````

Greedy left-to-right dollar parsing 3:

```````````````````````````````` example
$$x$$$$$$y$$
.
<p><code class="language-math math-inline">x$$$$$$y</code></p>
````````````````````````````````

Alpha then double dollar:

```````````````````````````````` example
alpha$$beta$gamma$$delta
.
<p>alpha<code class="language-math math-inline">beta$gamma</code>delta</p>
````````````````````````````````

## Block structure interactions

Block structure takes precedence — list interrupts math:

```````````````````````````````` example
$x + y - z$

$x + y
- z$

$$ x + y
> z $$
.
<p><code class="language-math math-inline">x + y - z</code></p>
<p>$x + y</p>
<ul>
<li>z$</li>
</ul>
<pre><code class="language-math math-display">> z $$</code></pre>
````````````````````````````````

Empty lines start new paragraph, breaking math:

```````````````````````````````` example
$not

math$

$$
not

math
$$
.
<p>$not</p>
<p>math$</p>
<pre><code class="language-math math-display">not

math</code></pre>
````````````````````````````````

Nested list structure breaks math:

```````````````````````````````` example
- $not
    - *
  math$
.
<ul>
<li>$not
<ul>
<li>*
math$</li>
</ul>
</li>
</ul>
````````````````````````````````

## Display math

Basic display math:

```````````````````````````````` example
$$
\beta+\gamma
$$
.
<pre><code class="language-math math-display">\beta+\gamma</code></pre>
````````````````````````````````

Display math after paragraph:

```````````````````````````````` example
**Bold**

$$
x = y
$$
.
<p><strong>Bold</strong></p>
<pre><code class="language-math math-display">x = y</code></pre>
````````````````````````````````

Display math with meta string:

```````````````````````````````` example
$$ meta
x
$$
.
<pre><code class="language-math math-display">x</code></pre>
````````````````````````````````

Empty display math:

```````````````````````````````` example
$$
$$
.
<pre><code class="language-math math-display"></code></pre>
````````````````````````````````

Multiple display math blocks:

```````````````````````````````` example
$$
a
$$

$$
b
$$
.
<pre><code class="language-math math-display">a</code></pre>
<pre><code class="language-math math-display">b</code></pre>
````````````````````````````````

Triple dollar fence:

```````````````````````````````` example
$$$
alpha
$$$
.
<pre><code class="language-math math-display">alpha</code></pre>
````````````````````````````````

Indented display math (up to 3 spaces):

```````````````````````````````` example
   $$
   x
   $$
.
<pre><code class="language-math math-display">x</code></pre>
````````````````````````````````

4-space indentation becomes code block:

```````````````````````````````` example
    $$
    x
    $$
.
<pre><code>$$
x
$$
</code></pre>
````````````````````````````````

Unterminated display math at end of document:

```````````````````````````````` example
$$
unterminated
.
<pre><code class="language-math math-display">unterminated</code></pre>
````````````````````````````````

Display math in list items:

```````````````````````````````` example
- $a$
- $$
  b
  $$
.
<ul>
<li><code class="language-math math-inline">a</code></li>
<li>
<pre><code class="language-math math-display">b</code></pre>
</li>
</ul>
````````````````````````````````

Display math interrupts paragraph:

```````````````````````````````` example
tango
$$
\alpha
$$
.
<p>tango</p>
<pre><code class="language-math math-display">\alpha</code></pre>
````````````````````````````````

Spacing before closing fence:

```````````````````````````````` example
$$
\alpha
  $$
.
<pre><code class="language-math math-display">\alpha</code></pre>
````````````````````````````````

Spacing after closing fence:

```````````````````````````````` example
$$
\alpha
$$  
.
<pre><code class="language-math math-display">\alpha</code></pre>
````````````````````````````````

Display math with blank lines in content:

```````````````````````````````` example
$$

  1
+ 1

= 2

$$
.
<pre><code class="language-math math-display">
  1
+ 1

= 2
</code></pre>
````````````````````````````````

Escaped delimiters are not math fences:

```````````````````````````````` example
Foo \$1$ bar

\$\$
1
\$\$
.
<p>Foo $1$ bar</p>
<p>$$
1
$$</p>
````````````````````````````````

Display math with Cauchy-Schwarz:

```````````````````````````````` example
**The Cauchy-Schwarz Inequality**

$$
\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)
$$
.
<p><strong>The Cauchy-Schwarz Inequality</strong></p>
<pre><code class="language-math math-display">\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)</code></pre>
````````````````````````````````

Display and inline in same list:

```````````````````````````````` example
- $a$

  $$
  a
  $$

- $$
  b
  $$
.
<ul>
<li>
<p><code class="language-math math-inline">a</code></p>
<pre><code class="language-math math-display">a</code></pre>
</li>
<li>
<pre><code class="language-math math-display">b</code></pre>
</li>
</ul>
````````````````````````````````

Display math in blockquote:

```````````````````````````````` example
> $$
> x
> $$
.
<blockquote>
<pre><code class="language-math math-display">x</code></pre>
</blockquote>
````````````````````````````````

Dollar in display text block:

```````````````````````````````` example
$$
\text{$b$}
$$
.
<pre><code class="language-math math-display">\text{$b$}</code></pre>
````````````````````````````````

Dollar-math with spaces on same line:

```````````````````````````````` example
When $a \ne 0$, there are two solutions to $(ax^2 + bx + c = 0)$ and they are
$$ x = {-b \pm \sqrt{b^2-4ac} \over 2a} $$
.
<p>When <code class="language-math math-inline">a \ne 0</code>, there are two solutions to <code class="language-math math-inline">(ax^2 + bx + c = 0)</code> and they are
<code class="language-math math-inline">x = {-b \pm \sqrt{b^2-4ac} \over 2a}</code></p>
````````````````````````````````

## Math in context

Math in link:

```````````````````````````````` example
[$a$](x)
.
<p><a href="x"><code class="language-math math-inline">a</code></a></p>
````````````````````````````````

Math preceded by various characters:

```````````````````````````````` example
$\pi$
'$\pi$
"$\pi$
($\pi$
[$\pi$
{$\pi$
/$\pi$
.
<p><code class="language-math math-inline">\pi</code>
'<code class="language-math math-inline">\pi</code>
"<code class="language-math math-inline">\pi</code>
(<code class="language-math math-inline">\pi</code>
[<code class="language-math math-inline">\pi</code>
{<code class="language-math math-inline">\pi</code>
/<code class="language-math math-inline">\pi</code></p>
````````````````````````````````

Inline math in italic text:

```````````````````````````````` example
_Equation $\Omega(69)$ in italic text_
.
<p><em>Equation <code class="language-math math-inline">\Omega(69)</code> in italic text</em></p>
````````````````````````````````

Inline math wrapped in quotes:

```````````````````````````````` example
$x$ $`y`$
.
<p><code class="language-math math-inline">x</code> <code class="language-math math-inline">`y`</code></p>
````````````````````````````````

Math vs HTML mix-up:

```````````````````````````````` example
$a <b > c$

$[(a+b)c](d+e)$

${a}_b c_{d}$
.
<p><code class="language-math math-inline">a &#x3C;b > c</code></p>
<p><code class="language-math math-inline">[(a+b)c](d+e)</code></p>
<p><code class="language-math math-inline">{a}_b c_{d}</code></p>
````````````````````````````````

Spacing around dollar sign in math mode:

```````````````````````````````` example
$x = \$$
.
<p>$x = $$</p>
````````````````````````````````

Math starting with negative sign:

```````````````````````````````` example
foo$-1+1 = 2$bar
.
<p>foo<code class="language-math math-inline">-1+1 = 2</code>bar</p>
````````````````````````````````

Images and math in same list:

```````````````````````````````` example
- ![node logo](https://nodejs.org/static/images/logo.svg)
- $x$
.
<ul>
<li><img src="https://nodejs.org/static/images/logo.svg" alt="node logo"></li>
<li><code class="language-math math-inline">x</code></li>
</ul>
````````````````````````````````