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
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
//! Markdown parser that builds [`Node`] values directly.
//!
//! Parsing runs in phases: [`block`] resolves the block structure line by line into a tree,
//! [`resolve`] collects the definitions and turns the tree into nodes, and [`inline`] parses the raw
//! text of paragraphs, headings and table cells along the way.
//!
//! It reads `CommonMark`, GFM, frontmatter, math and MDX (without a JavaScript parser, so expressions
//! only need balanced braces outside of strings and comments). HTML is rendered by [`render_html`].
mod block;
#[cfg(feature = "callout")]
mod callout;
mod code;
mod definition;
pub(crate) mod error;
mod flavor;
mod html_flow;
mod inline;
mod line;
mod mdx;
mod mdx_flow;
mod render_html;
mod resolve;
mod scan;
mod table;
mod tree;
use crate::node::Node;
use flavor::Flavor;
pub use error::{MdxDiagnostic, MdxError, MdxErrorKind, MdxFound, MdxPlace};
pub(crate) use inline::{is_autolink_email, normalize, unescape};
/// Parses `content` into a flat list of nodes.
#[cfg(test)]
pub(crate) fn parse(content: &str) -> miette::Result<Vec<Node>> {
parse_with(content, true)
}
/// Parses `content` into a flat list of nodes, with frontmatter at the start when `frontmatter` is set.
pub(crate) fn parse_with(content: &str, frontmatter: bool) -> miette::Result<Vec<Node>> {
let content = replace_nul(content);
let content = content.as_ref();
resolve::resolve(block::parse(content, Flavor::Markdown, frontmatter), Flavor::Markdown)
.map_err(|error| miette::Report::new(error.into_diagnostic(content)))
}
/// Replaces U+0000 with U+FFFD, as CommonMark requires.
fn replace_nul(content: &str) -> std::borrow::Cow<'_, str> {
if content.contains('\0') {
content.replace('\0', "\u{fffd}").into()
} else {
content.into()
}
}
/// Renders `content` as HTML.
pub(crate) fn to_html(content: &str) -> String {
render_html::render(&replace_nul(content))
}
/// Parses `content` as MDX: no indented code, HTML, autolinks or GFM, but expressions and JSX.
#[cfg(test)]
pub(crate) fn parse_mdx(content: &str) -> miette::Result<Vec<Node>> {
parse_mdx_with(content, true)
}
/// Parses `content` as MDX, with frontmatter at the start when `frontmatter` is set.
pub(crate) fn parse_mdx_with(content: &str, frontmatter: bool) -> miette::Result<Vec<Node>> {
let content = replace_nul(content);
let content = content.as_ref();
resolve::resolve(block::parse(content, Flavor::Mdx, frontmatter), Flavor::Mdx)
.map_err(|error| miette::Report::new(error.into_diagnostic(content)))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn nul_is_replaced_when_parsing() {
for nodes in [parse("# a\0b").unwrap(), parse_mdx("# a\0b").unwrap()] {
assert_eq!(nodes[0].to_string(), "# a\u{fffd}b");
}
}
#[test]
fn nul_autolink_matches_between_ast_and_html() {
let nodes = parse("<https://a\0b>").unwrap();
assert_eq!(nodes[0].to_string(), "[https://a\u{fffd}b](https://a\u{fffd}b)");
assert!(to_html("<https://a\0b>").contains("<a href=\"https://a%EF%BF%BDb\">"));
}
use proptest::prelude::*;
use proptest::test_runner::{RngAlgorithm, TestRng, TestRunner};
fn env_number<T: std::str::FromStr>(name: &str) -> Option<T> {
std::env::var(name).ok()?.parse().ok()
}
/// Lines built from container prefixes and block-level bodies only, so inline syntax never
/// appears. Constructs whose mdast positions depend on quirks of the following lines are left to the cases of `tests/parser_tree_tests.rs`: empty items and quotes,
/// unclosed fences, indented code next to containers, ordered lists that do not start at 1, and
/// lazy continuation inside nested containers, more than one container marker on a line, and runs
/// of setext underlines (`===` is only used by those cases).
fn block_input() -> impl Strategy<Value = String> {
// At most one container marker per line; deeper nesting comes from indentation.
let indent = prop::sample::select(vec!["", " ", " ", " "]);
let marker = prop::sample::select(vec!["", "> ", ">", "- ", "* ", "+ ", "1. ", "1) "]);
let body = prop::sample::select(vec![
"a",
"b",
"# a",
"#",
"## b ##",
"---",
"***",
"| a | b |",
"|-|:-:|",
"|1|2|3|",
"a|b",
"[a]: /u",
"[a]: /u 'T'",
"[^a]: x",
"<!-- c -->",
"x [a] [b][a] [^a]",
"*a* `b`",
"a ",
"a\\",
"+++",
]);
let block = (indent, marker, body).prop_map(|(indent, marker, body)| format!("{indent}{marker}{body}"));
let blank = prop::sample::select(vec!["", " "]).prop_map(str::to_string);
// Fences are always closed here.
let fence = (
prop::sample::select(vec!["", " ", " ", " "]),
prop::sample::select(vec![
("```", "```"),
("```rust x", "````"),
("~~~", "~~~"),
("$$", "$$"),
("$$ m", "$$$"),
]),
prop::sample::select(vec!["a", "", "> b", "- c"]),
)
.prop_map(|(indent, (open, close), content)| format!("{indent}{open}\n{indent}{content}\n{indent}{close}"));
let line = prop_oneof![8 => block, 2 => blank, 1 => fence];
(prop::collection::vec(line, 0..8), any::<bool>()).prop_map(|(lines, trailing_eol)| {
let mut input = lines.join("\n");
if trailing_eol {
input.push('\n');
}
input
})
}
/// Lines of inline syntax. Each line starts with `x` so that no line is a block on its own.
fn inline_input() -> impl Strategy<Value = String> {
let token = prop::sample::select(vec![
"a",
"b",
"foo",
" ",
" ",
"*",
"**",
"***",
"_",
"__",
"~",
"~~",
"`",
"``",
"[",
"]",
"(",
")",
"",
"][",
"]:",
"<a>",
"</a>",
"<x@y.z>",
"<http://a>",
]);
prop::collection::vec(token, 1..14).prop_map(|tokens| {
let mut input = String::from("x");
for token in tokens {
input.push_str(token);
if token == "\n" {
input.push('x');
}
}
input
})
}
/// Lines of MDX: tags, expressions and the Markdown around them.
fn mdx_input() -> impl Strategy<Value = String> {
let token = prop::sample::select(vec![
"<",
">",
"/",
"{",
"}",
"a",
"b",
"c",
" ",
" ",
"=",
"\"",
"'",
".",
":",
"-",
"*",
"_",
"`",
"[",
"]",
"(",
")",
"&",
"<a>",
"</a>",
"<b/>",
"<c d=\"e\">",
"<>",
"</>",
"{x}",
"{x {y}}",
"# ",
"- ",
"> ",
"\\",
"!",
"|",
"\n",
"\n\n",
"\n ",
"<a.b>",
"</a.b>",
"<a:b/>",
"{...c}",
"é",
"1. ",
]);
prop::collection::vec(token, 1..16).prop_map(|tokens| tokens.concat())
}
/// Markdown syntax mixed with multibyte text: CJK, emoji, combining marks, `ß`, full-width and
/// ideographic punctuation and spaces, and characters that change case or width.
fn unicode_input() -> impl Strategy<Value = String> {
let word = prop::sample::select(vec![
"あ",
"日本語",
"テスト",
"🎉",
"👨👩👧",
"é",
"e\u{301}",
"ß",
"Dž",
"İ",
"fi",
"www",
"www.あ.com",
"wwß",
"ww\u{301}",
"http://あ.jp/パス",
"https://例え.jp",
"a@あ.com",
"あ@b.com",
"。",
"、",
"「",
"」",
"(",
")",
"!",
"?",
"*",
"_",
"`",
"#",
"\u{3000}",
"\u{a0}",
"\u{200b}",
"\u{2028}",
"\u{feff}",
"\u{fe0f}",
"ا",
"א",
"𠮷",
"\u{10ffff}",
"\u{0}",
"x",
"foo",
]);
let syntax = prop::sample::select(vec![
" ",
" ",
"\t",
"*",
"**",
"_",
"__",
"~",
"~~",
"`",
"``",
"[",
"]",
"(",
")",
"![",
"<",
">",
"&",
"&",
"あ",
"🎉",
"&あ;",
"\\",
"|",
":",
"-",
"#",
"^",
"\"",
"'",
"{",
"}",
"/",
"=",
"://",
".",
"\n",
"\n\n",
"\n> ",
"\n- ",
"\n1. ",
"\n# ",
"\n| ",
"\n|-|-|\n",
"\n ",
"\n\t",
"\r\n",
"\n[a]: ",
"\n[^a]: ",
]);
let token = prop_oneof![3 => word, 2 => syntax];
prop::collection::vec(token, 1..24).prop_map(|tokens| tokens.concat())
}
/// Any characters at all, with extra weight on the ones that matter to Markdown.
fn arbitrary_input() -> impl Strategy<Value = String> {
let ch = prop_oneof![
4 => any::<char>(),
3 => prop::sample::select(vec!['*', '_', '`', '[', ']', '(', ')', '<', '>', '&', '|', '\\', '#', '-', '~', ' ', '\t', '\n', '!', 'w', 'h', '@', ':', '/', '.', '{', '}']),
3 => prop::sample::select(vec!['あ', 'é', 'ß', '🎉', '\u{301}', '\u{3000}', '\u{a0}', '。', '*']),
];
prop::collection::vec(ch, 0..40).prop_map(|chars| chars.into_iter().collect())
}
/// Closed fences whose info string and content are multibyte, alone or inside a container.
fn unicode_fence_input() -> impl Strategy<Value = String> {
let text = prop::sample::select(vec![
"あ",
"日本語 x",
"🎉",
"é",
"ß",
"www",
"a b",
"",
"> あ",
"- 🎉",
"\u{3000}",
]);
(
prop::sample::select(vec!["", "> ", "- ", " ", "1. "]),
prop::sample::select(vec![("```", "```"), ("~~~", "~~~"), ("````", "````"), ("$$", "$$")]),
text.clone(),
text.clone(),
text,
)
.prop_map(|(container, (open, close), info, first, second)| {
let pad = if container == "> " {
"> ".to_string()
} else {
" ".repeat(container.len())
};
let lead = |line: &str, first: bool| {
if first {
format!("{container}{line}")
} else {
format!("{pad}{line}")
}
};
[
lead(&format!("{open}{info}"), true),
lead(first, false),
lead(second, false),
lead(close, false),
]
.join("\n")
})
}
/// Checks what has to hold for any input: nothing panics, and every position lies inside the
/// document and does not end before it starts.
fn assert_valid(input: &str) {
let lines = 1 + input.matches(['\n', '\r']).count() - input.matches("\r\n").count();
let mut stack = parse(input).expect("Markdown always parses");
stack.extend(parse_mdx(input).unwrap_or_default());
while let Some(node) = stack.pop() {
if let Some(position) = node.position() {
let (start, end) = (&position.start, &position.end);
let ordered = (start.line, start.column) <= (end.line, end.column);
assert!(
ordered && start.line >= 1 && start.column >= 1 && end.line as usize <= lines,
"{node:?} has a position outside of {input:?}"
);
}
stack.extend(node.children());
}
let _ = to_html(input);
}
/// Runs `strategy` with a fixed seed so the outcome never varies between runs. `PROPTEST_CASES`
/// and `PARSER_TEST_SEED` widen the exploration.
fn check(strategy: impl Strategy<Value = String>) {
let config = ProptestConfig {
cases: env_number("PROPTEST_CASES").unwrap_or(3000),
failure_persistence: None,
..ProptestConfig::default()
};
let seed = env_number("PARSER_TEST_SEED").unwrap_or(7);
let mut runner = TestRunner::new_with_rng(config, TestRng::from_seed(RngAlgorithm::ChaCha, &[seed; 32]));
let result = runner.run(&strategy, |input| {
assert_valid(&input);
Ok(())
});
if let Err(error) = result {
panic!("{error}");
}
}
#[test]
fn block_structure_is_valid() {
check(block_input());
}
#[test]
fn inline_syntax_is_valid() {
check(inline_input());
}
#[test]
fn mdx_syntax_is_valid() {
check(mdx_input());
}
#[test]
fn multibyte_syntax_is_valid() {
check(unicode_input());
}
#[test]
fn multibyte_fences_are_valid() {
check(unicode_fence_input());
}
#[test]
fn arbitrary_text_is_valid() {
check(arbitrary_input());
}
/// Every control character and unusual space or separator at each syntax position.
#[test]
fn special_characters_are_valid() {
let chars = (0u32..=0x9f)
.chain([
0xa0, 0xad, 0x1680, 0x180e, 0x2000, 0x200a, 0x200b, 0x200d, 0x2028, 0x2029, 0x202f, 0x205f, 0x2060,
0x3000, 0xfeff, 0xfffd, 0xfe0f,
])
.filter_map(char::from_u32);
let templates = [
"[a]: {}",
"[a]: x{}y",
"[a]: <{}>",
"[a]: /u '{}'",
"[a]: /u {}",
"[a]\n\n[a]: {}x\n\n[a]",
"[a]({})",
"[a](x{}y)",
"[a](<{}>)",
"[a](/u '{}')",
"[a](/u \"{}\")",
"",
"[{}](x)",
"[x{}]: y",
"<http://a{}b>",
"<a@b{}c>",
"<{}a>",
"<a{}b>",
"<a {}b=c>",
"<a b={}c>",
"<a b=\"{}\">",
"http://a{}b.c",
"www.a{}b.c",
"www.a.b/{}x",
"x@y{}z.com",
"{}x@y.com",
"a{}b",
"{}a",
"a{}",
"a {}",
"{} a",
"# {}",
"# a{}",
"#{}a",
"{}# a",
"> {}",
"- {}",
"-{}a",
"1.{}a",
"1. {}",
"```{}",
"```a{}\nx\n```",
"```\n{}\n```",
"~~~{}",
"$${}",
"$$\n{}\n$$",
"`{}`",
"`a{}b`",
"*{}*",
"*a{}*",
"{}*a*",
"*a*{}",
"**{}**",
"_a{}_",
"_{}a_",
"~~a{}~~",
"~~{}~~",
"a\\{}",
"&{};",
"&a{};",
"&#{};",
"&#x{};",
"&{}",
"{}\n---",
"a{}\n---",
"a\n{}---",
"---{}",
"***{}",
"- - {}",
"| a{} | b |\n|-|-|",
"| {} |\n|-|\n| {} |",
"|{}|\n|{}|",
"[^a]: {}",
"[^a{}]: x",
"[^a]\n\n[^a]: {}x",
"x\n\n {}",
"x\n\n a{}",
"<!-- {} -->",
"<div>{}",
"<div {}>",
"<?{}?>",
"<![CDATA[{}]]>",
"---\n{}\n---\na",
"+++\n{}\n+++\na",
"{} \nb",
"a{}\nb",
"a\n{}b",
];
for char in chars {
for template in templates {
assert_valid(&template.replace("{}", &char.to_string()));
}
}
}
const SPEC_URL: &str =
"https://raw.githubusercontent.com/github/cmark-gfm/828322d1ee4facdab56f0d3edccb13e9af90dcd2/test/spec.txt";
const EXTENSIONS_SPEC_URL: &str = "https://raw.githubusercontent.com/github/cmark-gfm/828322d1ee4facdab56f0d3edccb13e9af90dcd2/test/extensions.txt";
const COMMONMARK_SPEC_URL: &str = "https://raw.githubusercontent.com/commonmark/commonmark-spec/0.31.2/spec.txt";
/// The markdown and the HTML of each example of the `CommonMark` and GFM `spec.txt`, with its number.
fn spec_examples(text: &str) -> Vec<(usize, String, String)> {
let fence = "`".repeat(32);
let open = format!("{fence} example");
let mut examples = Vec::new();
let mut lines = text.lines();
while let Some(line) = lines.next() {
if line != open {
continue;
}
let markdown = lines.by_ref().take_while(|line| *line != ".").collect::<Vec<_>>();
let html = lines.by_ref().take_while(|line| *line != fence).collect::<Vec<_>>();
// `→` stands for a tab in the spec.
let text = |lines: Vec<&str>| lines.join("\n").replace('\u{2192}', "\t");
let html = text(html);
let html = if html.is_empty() { html } else { html + "\n" };
examples.push((examples.len() + 1, text(markdown) + "\n", html));
}
examples
}
/// Examples of the GFM spec, which is based on `CommonMark` 0.29, that are not rendered as in the
/// spec, by number:
///
/// - a document that starts with `---` has frontmatter (66, 68)
/// - nested `strong` of runs of `*` and `_`, which `CommonMark` 0.30 and later render as nested
/// elements where 0.29 merged them (388, 416, 424, 425, 426, 463, 464, 465, 467)
/// - links with a protocol other than http, https, irc, ircs, mailto and xmpp have no `href`, as
/// as mdast to HTML does by default (594, 595, 597)
/// - GFM autolink literals, which the spec does not have (598, 604, 607, 608)
/// - the GFM tag filter, which writes the tags `script`, `style` and `textarea` as text (140, 141,
/// 142, 145, 147)
const KNOWN_DIFFERENCES: &[usize] = &[
66, 68, 140, 141, 142, 145, 147, 388, 416, 424, 425, 426, 463, 464, 465, 467, 594, 595, 597, 598, 604, 607, 608,
];
/// Examples of the GFM spec with `[[...]]` in them that the `wikilink` feature reads as a wikilink
/// (544, 555), and the one that either the `wikilink` or the `embed` feature changes (586).
const GFM_WIKILINK_DIFFERENCES: &[usize] = &[544, 555];
const GFM_OBSIDIAN_DIFFERENCES: &[usize] = &[586];
/// The same for the `CommonMark` 0.31.2 spec (548, 559 and 590).
const COMMONMARK_WIKILINK_DIFFERENCES: &[usize] = &[548, 559];
const COMMONMARK_OBSIDIAN_DIFFERENCES: &[usize] = &[590];
/// The examples that differ from the spec: `known`, and those that the enabled features read as
/// wikilinks and embeds.
fn expected_differences(known: &[usize], wikilink: &[usize], either: &[usize]) -> Vec<usize> {
let mut all = known.to_vec();
if cfg!(feature = "wikilink") {
all.extend_from_slice(wikilink);
}
if cfg!(any(feature = "wikilink", feature = "embed")) {
all.extend_from_slice(either);
}
all.sort_unstable();
all
}
/// Examples of the `CommonMark` 0.31.2 spec that are not rendered as in the spec, by number:
///
/// - a document that starts with `---` has frontmatter (96, 98)
/// - links with a protocol other than http, https, irc, ircs, mailto and xmpp have no `href` (598,
/// 599, 601)
/// - GFM autolink literals (602, 608, 611, 612)
/// - the GFM tag filter, which writes the tags `script`, `style` and `textarea` as text (170, 171, 172,
/// 173, 176, 178)
const COMMONMARK_KNOWN_DIFFERENCES: &[usize] =
&[96, 98, 170, 171, 172, 173, 176, 178, 598, 599, 601, 602, 608, 611, 612];
/// Examples of the GFM extensions spec that are not rendered as in the spec, by number:
///
/// - input that must only not crash, whose output the spec leaves out (20)
/// - the HTML of footnotes, which is the one of the current micromark and GitHub (23, 24, 25)
const EXTENSIONS_KNOWN_DIFFERENCES: &[usize] = &[20, 23, 24, 25];
/// Fetches `url`, or reads the file in the environment variable `var`.
fn spec_text(var: &str, url: &str) -> String {
match std::env::var(var) {
Ok(path) => std::fs::read_to_string(path).unwrap(),
Err(_) => ureq::get(url).call().unwrap().into_body().read_to_string().unwrap(),
}
}
/// The numbers of the examples of `text` that are not rendered as in the spec, and how many
/// examples there are. The count is also appended to the file in `SPEC_REPORT` as a table row.
fn differing_examples(name: &str, text: &str, minimum: usize) -> Vec<usize> {
let examples = spec_examples(text);
assert!(examples.len() > minimum, "only {} examples were found", examples.len());
let differing: Vec<usize> = examples
.iter()
.filter(|(_, markdown, html)| to_html(markdown) != *html)
.map(|(number, ..)| *number)
.collect();
write_report(name, examples.len(), differing.len());
differing
}
fn write_report(name: &str, total: usize, differing: usize) {
let passed = total - differing;
let features = if cfg!(feature = "obsidian") {
"obsidian"
} else {
"default"
};
let row = format!(
"| {name} | {features} | {passed} | {total} | {:.1}% |\n",
passed as f64 * 100.0 / total as f64
);
print!("{row}");
if let Ok(path) = std::env::var("SPEC_REPORT") {
use std::io::Write;
let mut file = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(path)
.unwrap();
file.write_all(row.as_bytes()).unwrap();
}
}
/// Renders every example of the spec to HTML, from `SPEC_FILE` or fetched over the network.
#[test]
#[ignore = "fetches spec.txt over the network; set SPEC_FILE to use a local copy"]
fn spec_examples_render_as_in_the_spec() {
assert_eq!(
differing_examples("GFM spec", &spec_text("SPEC_FILE", SPEC_URL), 600),
expected_differences(KNOWN_DIFFERENCES, GFM_WIKILINK_DIFFERENCES, GFM_OBSIDIAN_DIFFERENCES),
"examples that are not rendered as in the spec"
);
}
/// Renders every example of the `CommonMark` 0.31.2 spec to HTML, from `COMMONMARK_SPEC_FILE` or
/// fetched over the network.
#[test]
#[ignore = "fetches spec.txt over the network; set COMMONMARK_SPEC_FILE to use a local copy"]
fn commonmark_spec_examples_render_as_in_the_spec() {
assert_eq!(
differing_examples(
"CommonMark 0.31.2",
&spec_text("COMMONMARK_SPEC_FILE", COMMONMARK_SPEC_URL),
600
),
expected_differences(
COMMONMARK_KNOWN_DIFFERENCES,
COMMONMARK_WIKILINK_DIFFERENCES,
COMMONMARK_OBSIDIAN_DIFFERENCES
),
"examples that are not rendered as in the spec"
);
}
/// Renders every example of the GFM extensions spec to HTML, from `EXTENSIONS_SPEC_FILE` or fetched
/// over the network.
#[test]
#[ignore = "fetches extensions.txt over the network; set EXTENSIONS_SPEC_FILE to use a local copy"]
fn extensions_spec_examples_render_as_in_the_spec() {
assert_eq!(
differing_examples(
"GFM extensions",
&spec_text("EXTENSIONS_SPEC_FILE", EXTENSIONS_SPEC_URL),
20
),
EXTENSIONS_KNOWN_DIFFERENCES,
"examples that are not rendered as in the spec"
);
}
}