mdbook-template 1.1.1+deprecated

A mdbook preprocessor that allows the re-usability of template files with dynamic arguments
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
use std::collections::HashMap;
use std::path::{Path, PathBuf};

use fancy_regex::{CaptureMatches, Captures, Regex};
use lazy_static::lazy_static;
use mdbook::errors::Result;

use crate::FileReader;

const ESCAPE_CHAR: char = '\\';
const LINE_BREAKS: &[char] = &['\n', '\r'];

lazy_static! {
    // https://stackoverflow.com/questions/22871602/optimizing-regex-to-fine-key-value-pairs-space-delimited
    static ref TEMPLATE_ARGS: Regex = Regex::new(r"(?<=\s|\A)([^\s=]+)=(.*?)(?=(?:\s[^\s=]+=|$))").unwrap();

    // r"(?x)\\\{\{\#.*\}\}|\{\{\s*\#(template)\s+([\S]+)\s*\}\}|\{\{\s*\#(template)\s+([\S]+)\s+([^}]+)\}\}"
    static ref TEMPLATE: Regex = Regex::new(
        r"(?x)                              # enable insignificant whitespace mode

        \\\{\{                              # escaped link opening parens
        \#.*                                # match any character
        \}\}                                # escaped link closing parens

        |                                   # or

        \{\{\s*                             # link opening parens and whitespace(s)
        \#(template)                        # link type - template
        \s+                                 # separating whitespace
        ([\S]+)                             # relative path to template file
        \s*                                 # optional separating whitespaces(s)
        \}\}                                # link closing parens

        |                                   # or

        \{\{\s*                             # link opening parens and whitespace(s)
        \#(template)                        # link type - template
        \s+                                 # separating whitespace
        ([\S]+)                             # relative path to template file
        \s+                                 # separating whitespace(s)
        ([^}]+)                             # get all template arguments
        \}\}                                # link closing parens"
    )
    .unwrap();

    // r"(?x)\\\[\[.*\]\]|\[\[\s*\#([\S]+)\s*\]\]|\[\[\s*\#([\S]+)\s+([^]]+)\]\]"
    static ref ARGS: Regex = Regex::new(
        r"(?x)                                  # enable insignificant whitespace mode

        \\\[\[                                  # escaped link opening square brackets
        \#.*                                    # match any character
        \]\]                                    # escaped link closing parens

        |                                       # or

        \[\[\s*                                 # link opening parens and whitespace(s)
        \#([\S]+)                               # arg name
        \s*                                     # optional separating whitespace(s)
        \]\]                                    # link closing parens

        |                                       # or

        \[\[\s*                                 # link opening parens and whitespace(s)
        \#([\S]+)                               # arg name
        \s+                                     # optional separating whitespace(s)
        ([^]]+)                                 # match everything after space
        \]\]                                    # link closing parens"
    )
    .unwrap();
}

#[derive(PartialEq, Debug)]
pub(crate) struct Link<'a> {
    pub(crate) start_index: usize,
    pub(crate) end_index: usize,
    pub(crate) link_type: LinkType,
    pub(crate) link_text: &'a str,
    args: HashMap<&'a str, &'a str>,
}

impl<'a> Link<'a> {
    fn from_capture(cap: Captures<'a>) -> Option<Link<'a>> {
        let mut all_args = HashMap::with_capacity(20);

        // https://regex101.com/r/OBywLv/1
        let link_type = match (
            cap.get(0),
            cap.get(1),
            cap.get(2),
            cap.get(3),
            cap.get(4),
            cap.get(5),
        ) {
            // This looks like {{#template <file>}}
            (_, _, Some(file), None, None, None) => {
                Some(LinkType::Template(PathBuf::from(file.as_str())))
            }
            // This looks like \{{#<whatever string>}}
            (Some(mat), _, _, _, _, _) if mat.as_str().starts_with(ESCAPE_CHAR) => {
                Some(LinkType::Escaped)
            }
            (_, None, None, _, Some(file), Some(args)) => {
                let split_args = match args.as_str().contains(LINE_BREAKS) {
                    /*
                    This looks like
                       {{#template
                           <file>
                           <args>
                       }}
                    */
                    true => args
                        .as_str()
                        .split(LINE_BREAKS)
                        .map(|str| str.trim())
                        .filter(|trimmed| !trimmed.is_empty())
                        .filter_map(|mat| {
                            let mut split_n = mat.splitn(2, '=');
                            if let Some(key) = split_n.next() {
                                let key = key.trim();
                                if let Some(value) = split_n.next() {
                                    return Some((key, value));
                                }
                            }
                            eprintln!(
                                "Couldn't find a key/value pair while parsing the argument '{}'",
                                mat
                            );
                            None
                        })
                        .collect::<Vec<_>>(),

                    // This looks like {{#template <file> <args>}}
                    false => TEMPLATE_ARGS
                        .captures_iter(args.as_str())
                        .filter_map(|mat| {
                            let captures = mat.ok()?;
                            let mut split_n = captures.get(0)?.as_str().splitn(2, '=');
                            if let Some(key) = split_n.next() {
                                let key = key.trim();
                                if let Some(value) = split_n.next() {
                                    return Some((key.trim(), value));
                                }
                            }
                            eprintln!(
                                "Couldn't parse key or value while parsing '{:?}'",
                                &args.as_str()
                            );
                            None
                        })
                        .collect::<Vec<_>>(),
                };

                all_args.extend(split_args);
                Some(LinkType::Template(PathBuf::from(file.as_str())))
            }
            _ => None,
        };

        link_type.and_then(|lnk_type| {
            cap.get(0).map(|mat| Link {
                start_index: mat.start(),
                end_index: mat.end(),
                link_type: lnk_type,
                link_text: mat.as_str(),
                args: all_args,
            })
        })
    }

    pub(crate) fn replace_args<P, FR>(&self, base: P, file_reader: &FR) -> Result<String>
    where
        P: AsRef<Path>,
        FR: FileReader,
    {
        match self.link_type {
            LinkType::Escaped => Ok((self.link_text[1..]).to_owned()),
            LinkType::Template(ref pat) => {
                let target = base.as_ref().join(pat);
                let contents = file_reader.read_to_string(&target, self.link_text)?;
                Ok(Args::replace(contents.as_str(), &self.args))
            }
        }
    }
}

#[derive(PartialEq, Debug)]
pub(crate) enum LinkType {
    Escaped,
    Template(PathBuf),
}

impl LinkType {
    pub(crate) fn relative_path<P: AsRef<Path>>(self, base: P) -> Option<PathBuf> {
        match self {
            LinkType::Escaped => None,
            LinkType::Template(path) => Some(
                base.as_ref()
                    .join(path)
                    .parent()
                    .expect("Included file should not be /")
                    .to_path_buf(),
            ),
        }
    }
}

pub(crate) struct LinkIter<'a>(CaptureMatches<'a, 'a>);

impl<'a> Iterator for LinkIter<'a> {
    type Item = Link<'a>;

    fn next(&mut self) -> Option<Self::Item> {
        for cap in &mut self.0 {
            if let Some(inc) = Link::from_capture(cap.ok()?) {
                return Some(inc);
            }
        }
        None
    }
}

pub(crate) fn extract_template_links(contents: &str) -> LinkIter<'_> {
    LinkIter(TEMPLATE.captures_iter(contents))
}

#[derive(PartialEq, Debug)]
struct Args<'a> {
    start_index: usize,
    end_index: usize,
    args_type: ArgsType<'a>,
    args_text: &'a str,
}

impl<'a> Args<'a> {
    fn replace(contents: &str, all_args: &HashMap<&str, &str>) -> String {
        // Must keep track of indices as they will not correspond after string substitution
        let mut previous_end_index = 0;
        let mut replaced = String::with_capacity(contents.len());

        for captured_arg in extract_args(contents) {
            replaced.push_str(&contents[previous_end_index..captured_arg.start_index]);

            match captured_arg.args_type {
                ArgsType::Escaped => replaced.push_str(&captured_arg.args_text[1..]),
                ArgsType::Plain(argument) => match all_args.get(argument) {
                    None => {}
                    Some(value) => replaced.push_str(value),
                },
                ArgsType::Default(argument, default_value) => match all_args.get(argument) {
                    None => replaced.push_str(default_value),
                    Some(value) => replaced.push_str(value),
                },
            }

            previous_end_index = captured_arg.end_index;
        }

        replaced.push_str(&contents[previous_end_index..]);
        replaced
    }

    fn from_capture(cap: Captures<'a>) -> Option<Args<'a>> {
        // https://regex101.com/r/lKSOOl/4
        let arg_type = match (cap.get(0), cap.get(1), cap.get(2), cap.get(3)) {
            // This looks like [[#path]]
            (_, Some(argument), None, None) => Some(ArgsType::Plain(argument.as_str())),
            // This looks like [[#path ../images]]
            (_, _, Some(argument), Some(default_value)) => {
                Some(ArgsType::Default(argument.as_str(), default_value.as_str()))
            }
            // This looks like \[[#any string]]
            (Some(mat), _, _, _) if mat.as_str().starts_with(ESCAPE_CHAR) => {
                Some(ArgsType::Escaped)
            }
            _ => None,
        };

        arg_type.and_then(|arg_type| {
            cap.get(0).map(|capt| Args {
                start_index: capt.start(),
                end_index: capt.end(),
                args_type: arg_type,
                args_text: capt.as_str(),
            })
        })
    }
}

#[derive(PartialEq, Debug)]
enum ArgsType<'a> {
    Escaped,
    Plain(&'a str),
    Default(&'a str, &'a str),
}

struct ArgsIter<'a>(CaptureMatches<'a, 'a>);

impl<'a> Iterator for ArgsIter<'a> {
    type Item = Args<'a>;

    fn next(&mut self) -> Option<Self::Item> {
        for cap in &mut self.0 {
            if let Some(inc) = Args::from_capture(cap.unwrap()) {
                return Some(inc);
            }
        }
        None
    }
}

fn extract_args(contents: &str) -> ArgsIter<'_> {
    ArgsIter(ARGS.captures_iter(contents))
}

#[cfg(test)]
mod link_tests {
    use std::collections::HashMap;
    use std::path::PathBuf;

    use crate::links::{extract_args, extract_template_links, Args, ArgsType, Link, LinkType};

    #[test]
    fn test_extract_zero_template_links() {
        let s = "This is some text without any template links";
        assert_eq!(extract_template_links(s).collect::<Vec<_>>(), vec![])
    }

    #[test]
    fn test_extract_template_links_partial_match() {
        let s = "Some random text with {{#template...";
        assert_eq!(extract_template_links(s).collect::<Vec<_>>(), vec![]);
        let s = "Some random text with {{#template footer.md...";
        assert_eq!(extract_template_links(s).collect::<Vec<_>>(), vec![]);
        let s = "Some random text with {{#template footer.md path=../images...";
        assert_eq!(extract_template_links(s).collect::<Vec<_>>(), vec![]);
        let s = "Some random text with \\{{#template...";
        assert_eq!(extract_template_links(s).collect::<Vec<_>>(), vec![]);
    }

    #[test]
    fn test_extract_template_links_empty() {
        let s = "Some random text with {{}} {{#}}...";
        assert_eq!(extract_template_links(s).collect::<Vec<_>>(), vec![]);
    }

    #[test]
    fn test_extract_template_links_unknown() {
        let s = "Some random text with {{#templatee file.rs}} and {{#include}} {{#playground}} {{#tempate}}...";
        assert!(extract_template_links(s).collect::<Vec<_>>() == vec![]);
    }

    #[test]
    fn test_extract_zero_template_links_without_args() {
        let s = "{{#template templates/footer.md}}";

        let res = extract_template_links(s).collect::<Vec<_>>();

        assert_eq!(
            res,
            vec![Link {
                start_index: 0,
                end_index: 33,
                link_type: LinkType::Template(PathBuf::from("templates/footer.md")),
                link_text: "{{#template templates/footer.md}}",
                args: HashMap::new()
            },]
        );
    }

    #[test]
    fn test_extract_template_links_simple() {
        let s =
            "Some random text with {{#template file.rs}} and {{#template test.rs lang=rust}}...";

        let res = extract_template_links(s).collect::<Vec<_>>();

        assert_eq!(
            res,
            vec![
                Link {
                    start_index: 22,
                    end_index: 43,
                    link_type: LinkType::Template(PathBuf::from("file.rs")),
                    link_text: "{{#template file.rs}}",
                    args: HashMap::new()
                },
                Link {
                    start_index: 48,
                    end_index: 79,
                    link_type: LinkType::Template(PathBuf::from("test.rs")),
                    link_text: "{{#template test.rs lang=rust}}",
                    args: HashMap::from([("lang", "rust")])
                },
            ]
        );
    }

    #[test]
    fn test_extract_template_links_simple_with_equals_sign() {
        let s = "Some random text with{{#template test.rs lang=rust math=2+2=4}}...";

        let res = extract_template_links(s).collect::<Vec<_>>();

        assert_eq!(
            res,
            vec![Link {
                start_index: 21,
                end_index: 63,
                link_type: LinkType::Template(PathBuf::from("test.rs")),
                link_text: "{{#template test.rs lang=rust math=2+2=4}}",
                args: HashMap::from([("lang", "rust"), ("math", "2+2=4")]),
            },]
        );
    }

    #[test]
    fn test_extract_template_links_simple_with_whitespace() {
        let s = "Some random text with {{#template test.rs lang=rust authors=Goudham & Hazel}}...";

        let res = extract_template_links(s).collect::<Vec<_>>();

        assert_eq!(
            res,
            vec![Link {
                start_index: 22,
                end_index: 77,
                link_type: LinkType::Template(PathBuf::from("test.rs")),
                link_text: "{{#template test.rs lang=rust authors=Goudham & Hazel}}",
                args: HashMap::from([("lang", "rust"), ("authors", "Goudham & Hazel")]),
            },]
        );
    }

    #[test]
    fn test_extract_template_links_simple_with_tabs() {
        let s = "Some random text with {{#template      test.rs      lang=rust authors=Goudham & Hazel}}...";

        let res = extract_template_links(s).collect::<Vec<_>>();

        assert_eq!(
            res,
            vec![Link {
                start_index: 22,
                end_index: 87,
                link_type: LinkType::Template(PathBuf::from("test.rs")),
                link_text: "{{#template      test.rs      lang=rust authors=Goudham & Hazel}}",
                args: HashMap::from([("lang", "rust"), ("authors", "Goudham & Hazel")]),
            },]
        );
    }

    #[test]
    fn test_extract_template_links_with_special_characters() {
        let s = "Some random text with {{#template foo-bar\\-baz/_c++.'.rs path=images}}...";

        let res = extract_template_links(s).collect::<Vec<_>>();

        assert_eq!(
            res,
            vec![Link {
                start_index: 22,
                end_index: 70,
                link_type: LinkType::Template(PathBuf::from("foo-bar\\-baz/_c++.'.rs")),
                link_text: "{{#template foo-bar\\-baz/_c++.'.rs path=images}}",
                args: HashMap::from([("path", "images")]),
            },]
        );
    }

    #[test]
    fn test_extract_template_links_newlines() {
        let s = "{{#template
            test.rs
            lang=rust
            authors=Goudham & Hazel
            year=2022
        }}";

        let res = extract_template_links(s).collect::<Vec<_>>();

        assert_eq!(
            res,
            vec![Link {
                start_index: 0,
                end_index: 122,
                link_type: LinkType::Template(PathBuf::from("test.rs")),
                link_text: "{{#template\n            test.rs\n            lang=rust\n            authors=Goudham & Hazel\n            year=2022\n        }}",
                args: HashMap::from([("lang", "rust"), ("authors", "Goudham & Hazel"), ("year", "2022")]),
            },]
        );
    }

    #[test]
    fn test_extract_template_links_with_newlines_tabs() {
        let s = "{{#template
    test.rs
lang=rust
        authors=Goudham & Hazel
year=2022
}}";

        let res = extract_template_links(s).collect::<Vec<_>>();

        assert_eq!(
            res,
            vec![Link {
                start_index: 0,
                end_index: 78,
                link_type: LinkType::Template(PathBuf::from("test.rs")),
                link_text: "{{#template\n    test.rs\nlang=rust\n        authors=Goudham & Hazel\nyear=2022\n}}",
                args: HashMap::from([("lang", "rust"), ("authors", "Goudham & Hazel"), ("year", "2022")]),
            },]
        );
    }

    #[test]
    fn test_extract_template_links_with_newlines_malformed() {
        let s = [
            "{{#template test.rs \n",
            "        lang=rust\n",
            "        year=2022}}",
        ]
        .concat();

        let res = extract_template_links(&s).collect::<Vec<_>>();

        assert_eq!(
            res,
            vec![Link {
                start_index: 0,
                end_index: 58,
                link_type: LinkType::Template(PathBuf::from("test.rs")),
                link_text: "{{#template test.rs \n        lang=rust\n        year=2022}}",
                args: HashMap::from([("lang", "rust"), ("year", "2022")]),
            },]
        );
    }

    #[test]
    fn test_extract_zero_args() {
        let s = "This is some text without any template links";
        assert_eq!(extract_args(s).collect::<Vec<_>>(), vec![])
    }

    #[test]
    fn test_extract_args_partial_match() {
        let s = "Some random text with [[#height...";
        assert_eq!(extract_args(s).collect::<Vec<_>>(), vec![]);
        let s = "Some random text with [[#image ferris.png...";
        assert_eq!(extract_args(s).collect::<Vec<_>>(), vec![]);
        let s = "Some random text with [[#width 550...";
        assert_eq!(extract_args(s).collect::<Vec<_>>(), vec![]);
        let s = "Some random text with \\[[#title...";
        assert_eq!(extract_args(s).collect::<Vec<_>>(), vec![]);
    }

    #[test]
    fn test_extract_args_empty() {
        let s = "Some random text with [[]] [[#]]...";
        assert_eq!(extract_args(s).collect::<Vec<_>>(), vec![]);
    }

    #[test]
    fn test_extract_args_simple() {
        let s = "This is some random text with [[#path]] and then some more random text";

        let res = extract_args(s).collect::<Vec<_>>();

        assert_eq!(
            res,
            vec![Args {
                start_index: 30,
                end_index: 39,
                args_type: ArgsType::Plain("path"),
                args_text: "[[#path]]"
            }]
        );
    }

    #[test]
    fn test_extract_args_escaped() {
        let start = r"
        Example Text
        \[[#height 200px]] << an escaped argument!
        ";
        let end = r"
        Example Text
        [[#height 200px]] << an escaped argument!
        ";
        assert_eq!(Args::replace(start, &HashMap::<&str, &str>::new()), end);
    }

    #[test]
    fn test_extract_args_with_spaces() {
        let s1 = "This is some random text with [[     #path       ]]";
        let s2 = "This is some random text with [[#path       ]]";
        let s3 = "This is some random text with [[     #path]]";

        let res1 = extract_args(s1).collect::<Vec<_>>();
        let res2 = extract_args(s2).collect::<Vec<_>>();
        let res3 = extract_args(s3).collect::<Vec<_>>();

        assert_eq!(
            res1,
            vec![Args {
                start_index: 30,
                end_index: 51,
                args_type: ArgsType::Plain("path"),
                args_text: "[[     #path       ]]"
            }]
        );

        assert_eq!(
            res2,
            vec![Args {
                start_index: 30,
                end_index: 46,
                args_type: ArgsType::Plain("path"),
                args_text: "[[#path       ]]"
            }]
        );

        assert_eq!(
            res3,
            vec![Args {
                start_index: 30,
                end_index: 44,
                args_type: ArgsType::Plain("path"),
                args_text: "[[     #path]]"
            }]
        );
    }

    #[test]
    fn test_extract_args_with_default_value() {
        let s = "This is some random text with [[#path 200px]] and then some more random text";

        let res = extract_args(s).collect::<Vec<_>>();

        assert_eq!(
            res,
            vec![Args {
                start_index: 30,
                end_index: 45,
                args_type: ArgsType::Default("path", "200px"),
                args_text: "[[#path 200px]]"
            }]
        );
    }

    #[test]
    fn test_extract_args_with_default_value_and_spaces() {
        let s =
            "This is some random text with [[   #path   400px  ]] and then some more random text";

        let res = extract_args(s).collect::<Vec<_>>();

        assert_eq!(
            res,
            vec![Args {
                start_index: 30,
                end_index: 52,
                args_type: ArgsType::Default("path", "400px  "),
                args_text: "[[   #path   400px  ]]"
            }]
        );
    }

    #[test]
    fn test_extract_args_with_multiple_spaced_default_value() {
        let s = "[[#title An Amazing Title]]";

        let res = extract_args(s).collect::<Vec<_>>();

        assert_eq!(
            res,
            vec![Args {
                start_index: 0,
                end_index: 27,
                args_type: ArgsType::Default("title", "An Amazing Title"),
                args_text: "[[#title An Amazing Title]]"
            }]
        );
    }

    #[test]
    fn test_replace_args_simple() {
        let start = r"
        Example Text
        [[#height]] << an argument!
        ";
        let end = r"
        Example Text
        200px << an argument!
        ";
        assert_eq!(
            Args::replace(start, &HashMap::from([("height", "200px")])),
            end
        );
    }

    #[test]
    fn test_replace_args_with_default() {
        let start = r"
        Example Text
        [[#height 300px]] << an argument!
        ";
        let end = r"
        Example Text
        300px << an argument!
        ";
        assert_eq!(Args::replace(start, &HashMap::<&str, &str>::new()), end);
    }

    #[test]
    fn test_replace_args_overriding_default() {
        let start = r"
        Example Text
        [[#height 300px]] << an argument!
        ";
        let end = r"
        Example Text
        200px << an argument!
        ";
        assert_eq!(
            Args::replace(start, &HashMap::from([("height", "200px")])),
            end
        );
    }
}