maudit 0.11.0

Library for generating static websites.
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
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
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BlockQuoteKind {
    Note,
    Tip,
    Important,
    Warning,
    Caution,
}

impl From<pulldown_cmark::BlockQuoteKind> for BlockQuoteKind {
    fn from(kind: pulldown_cmark::BlockQuoteKind) -> Self {
        match kind {
            pulldown_cmark::BlockQuoteKind::Note => BlockQuoteKind::Note,
            pulldown_cmark::BlockQuoteKind::Tip => BlockQuoteKind::Tip,
            pulldown_cmark::BlockQuoteKind::Important => BlockQuoteKind::Important,
            pulldown_cmark::BlockQuoteKind::Warning => BlockQuoteKind::Warning,
            pulldown_cmark::BlockQuoteKind::Caution => BlockQuoteKind::Caution,
        }
    }
}

impl From<&pulldown_cmark::BlockQuoteKind> for BlockQuoteKind {
    fn from(kind: &pulldown_cmark::BlockQuoteKind) -> Self {
        (*kind).into()
    }
}

impl BlockQuoteKind {
    pub fn as_str(&self) -> &'static str {
        match self {
            BlockQuoteKind::Note => "note",
            BlockQuoteKind::Tip => "tip",
            BlockQuoteKind::Important => "important",
            BlockQuoteKind::Warning => "warning",
            BlockQuoteKind::Caution => "caution",
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LinkType {
    Inline,
    Reference,
    ReferenceUnknown,
    Collapsed,
    CollapsedUnknown,
    Shortcut,
    ShortcutUnknown,
    Autolink,
    Email,
    WikiLink(bool),
}

impl From<pulldown_cmark::LinkType> for LinkType {
    fn from(link_type: pulldown_cmark::LinkType) -> Self {
        match link_type {
            pulldown_cmark::LinkType::Inline => LinkType::Inline,
            pulldown_cmark::LinkType::Reference => LinkType::Reference,
            pulldown_cmark::LinkType::ReferenceUnknown => LinkType::ReferenceUnknown,
            pulldown_cmark::LinkType::Collapsed => LinkType::Collapsed,
            pulldown_cmark::LinkType::CollapsedUnknown => LinkType::CollapsedUnknown,
            pulldown_cmark::LinkType::Shortcut => LinkType::Shortcut,
            pulldown_cmark::LinkType::ShortcutUnknown => LinkType::ShortcutUnknown,
            pulldown_cmark::LinkType::Autolink => LinkType::Autolink,
            pulldown_cmark::LinkType::Email => LinkType::Email,
            pulldown_cmark::LinkType::WikiLink { has_pothole } => LinkType::WikiLink(has_pothole),
        }
    }
}

impl From<&pulldown_cmark::LinkType> for LinkType {
    fn from(link_type: &pulldown_cmark::LinkType) -> Self {
        (*link_type).into()
    }
}

impl LinkType {
    pub fn as_str(&self) -> &'static str {
        match self {
            LinkType::Inline => "inline",
            LinkType::Reference => "reference",
            LinkType::ReferenceUnknown => "reference_unknown",
            LinkType::Collapsed => "collapsed",
            LinkType::CollapsedUnknown => "collapsed_unknown",
            LinkType::Shortcut => "shortcut",
            LinkType::ShortcutUnknown => "shortcut_unknown",
            LinkType::Autolink => "autolink",
            LinkType::Email => "email",
            LinkType::WikiLink(_) => "wikilink",
        }
    }
}

pub trait HeadingComponent {
    fn render_start(&self, level: u8, id: Option<&str>, classes: &[&str]) -> String {
        let class_attr = if !classes.is_empty() {
            format!(" class=\"{}\"", classes.join(" "))
        } else {
            String::new()
        };

        let id_attr = id
            .as_ref()
            .map(|i| format!(" id=\"{}\"", i))
            .unwrap_or_default();

        format!("<h{}{}{}>", level, id_attr, class_attr)
    }

    fn render_end(&self, level: u8) -> String {
        format!("</h{}>", level)
    }
}

pub trait ParagraphComponent {
    fn render_start(&self) -> String {
        "<p>".to_string()
    }

    fn render_end(&self) -> String {
        "</p>".to_string()
    }
}

pub trait LinkComponent {
    fn render_start(&self, url: &str, title: Option<&str>, link_type: LinkType) -> String;

    fn render_end(&self) -> String {
        "</a>".to_string()
    }
}

pub trait ImageComponent {
    fn render(&self, url: &str, alt: &str, title: Option<&str>) -> String;
}

pub trait StrongComponent {
    fn render_start(&self) -> String {
        "<strong>".to_string()
    }

    fn render_end(&self) -> String {
        "</strong>".to_string()
    }
}

pub trait EmphasisComponent {
    fn render_start(&self) -> String {
        "<em>".to_string()
    }

    fn render_end(&self) -> String {
        "</em>".to_string()
    }
}

pub trait CodeComponent {
    fn render(&self, code: &str) -> String;
}

pub trait BlockquoteComponent {
    fn render_start(&self, kind: Option<BlockQuoteKind>) -> String {
        match kind {
            Some(k) => format!("<blockquote data-kind=\"{}\">", k.as_str()),
            None => "<blockquote>".to_string(),
        }
    }

    fn render_end(&self, _kind: Option<BlockQuoteKind>) -> String {
        "</blockquote>".to_string()
    }
}

pub trait HardBreakComponent {
    fn render(&self) -> String {
        "<br />".to_string()
    }
}

pub trait HorizontalRuleComponent {
    fn render(&self) -> String {
        "<hr />".to_string()
    }
}

pub trait ListComponent {
    fn render_start(&self, list_type: ListType, start_number: Option<u64>) -> String {
        match list_type {
            ListType::Ordered => {
                if let Some(start) = start_number {
                    if start != 1 {
                        format!("<ol start=\"{}\">", start)
                    } else {
                        "<ol>".to_string()
                    }
                } else {
                    "<ol>".to_string()
                }
            }
            ListType::Unordered => "<ul>".to_string(),
        }
    }

    fn render_end(&self, list_type: ListType) -> String {
        match list_type {
            ListType::Ordered => "</ol>".to_string(),
            ListType::Unordered => "</ul>".to_string(),
        }
    }
}

pub trait ListItemComponent {
    fn render_start(&self) -> String {
        "<li>".to_string()
    }

    fn render_end(&self) -> String {
        "</li>".to_string()
    }
}

pub trait StrikethroughComponent {
    fn render_start(&self) -> String {
        "<del>".to_string()
    }

    fn render_end(&self) -> String {
        "</del>".to_string()
    }
}

pub trait TaskListMarkerComponent {
    fn render(&self, checked: bool) -> String {
        if checked {
            "<input type=\"checkbox\" checked disabled />".to_string()
        } else {
            "<input type=\"checkbox\" disabled />".to_string()
        }
    }
}

pub trait TableComponent {
    fn render_start(&self, _column_alignments: &[TableAlignment]) -> String {
        "<table>".to_string()
    }

    fn render_end(&self) -> String {
        "</table>".to_string()
    }
}

pub trait TableHeadComponent {
    fn render_start(&self) -> String {
        "<thead>".to_string()
    }

    fn render_end(&self) -> String {
        "</thead>".to_string()
    }
}

pub trait TableRowComponent {
    fn render_start(&self) -> String {
        "<tr>".to_string()
    }

    fn render_end(&self) -> String {
        "</tr>".to_string()
    }
}

pub trait TableCellComponent {
    fn render_start(&self, is_header: bool, alignment: Option<TableAlignment>) -> String {
        let tag = if is_header { "th" } else { "td" };
        match alignment {
            Some(TableAlignment::Left) => format!("<{} style=\"text-align: left\">", tag),
            Some(TableAlignment::Center) => format!("<{} style=\"text-align: center\">", tag),
            Some(TableAlignment::Right) => format!("<{} style=\"text-align: right\">", tag),
            None => format!("<{}>", tag),
        }
    }

    fn render_end(&self, is_header: bool) -> String {
        if is_header {
            "</th>".to_string()
        } else {
            "</td>".to_string()
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ListType {
    Ordered,
    Unordered,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TableAlignment {
    Left,
    Center,
    Right,
}

#[derive(Default)]
pub struct MarkdownComponents {
    pub heading: Option<Box<dyn HeadingComponent + Send + Sync>>,
    pub paragraph: Option<Box<dyn ParagraphComponent + Send + Sync>>,
    pub link: Option<Box<dyn LinkComponent + Send + Sync>>,
    pub image: Option<Box<dyn ImageComponent + Send + Sync>>,
    pub strong: Option<Box<dyn StrongComponent + Send + Sync>>,
    pub emphasis: Option<Box<dyn EmphasisComponent + Send + Sync>>,
    pub code: Option<Box<dyn CodeComponent + Send + Sync>>,
    pub blockquote: Option<Box<dyn BlockquoteComponent + Send + Sync>>,
    pub hard_break: Option<Box<dyn HardBreakComponent + Send + Sync>>,
    pub horizontal_rule: Option<Box<dyn HorizontalRuleComponent + Send + Sync>>,
    pub list: Option<Box<dyn ListComponent + Send + Sync>>,
    pub list_item: Option<Box<dyn ListItemComponent + Send + Sync>>,
    pub strikethrough: Option<Box<dyn StrikethroughComponent + Send + Sync>>,
    pub task_list_marker: Option<Box<dyn TaskListMarkerComponent + Send + Sync>>,
    pub table: Option<Box<dyn TableComponent + Send + Sync>>,
    pub table_head: Option<Box<dyn TableHeadComponent + Send + Sync>>,
    pub table_row: Option<Box<dyn TableRowComponent + Send + Sync>>,
    pub table_cell: Option<Box<dyn TableCellComponent + Send + Sync>>,
}

impl MarkdownComponents {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn has_any_components(&self) -> bool {
        self.heading.is_some()
            || self.paragraph.is_some()
            || self.link.is_some()
            || self.image.is_some()
            || self.strong.is_some()
            || self.emphasis.is_some()
            || self.code.is_some()
            || self.blockquote.is_some()
            || self.hard_break.is_some()
            || self.horizontal_rule.is_some()
            || self.list.is_some()
            || self.list_item.is_some()
            || self.strikethrough.is_some()
            || self.task_list_marker.is_some()
            || self.table.is_some()
            || self.table_head.is_some()
            || self.table_row.is_some()
            || self.table_cell.is_some()
    }

    /// Set a custom heading component
    pub fn heading<C: HeadingComponent + Send + Sync + 'static>(mut self, component: C) -> Self {
        self.heading = Some(Box::new(component));
        self
    }

    /// Set a custom paragraph component
    pub fn paragraph<C: ParagraphComponent + Send + Sync + 'static>(
        mut self,
        component: C,
    ) -> Self {
        self.paragraph = Some(Box::new(component));
        self
    }

    /// Set a custom link component
    pub fn link<C: LinkComponent + Send + Sync + 'static>(mut self, component: C) -> Self {
        self.link = Some(Box::new(component));
        self
    }

    /// Set a custom image component
    pub fn image<C: ImageComponent + Send + Sync + 'static>(mut self, component: C) -> Self {
        self.image = Some(Box::new(component));
        self
    }

    /// Set a custom strong component
    pub fn strong<C: StrongComponent + Send + Sync + 'static>(mut self, component: C) -> Self {
        self.strong = Some(Box::new(component));
        self
    }

    /// Set a custom emphasis component
    pub fn emphasis<C: EmphasisComponent + Send + Sync + 'static>(mut self, component: C) -> Self {
        self.emphasis = Some(Box::new(component));
        self
    }

    /// Set a custom code component
    pub fn code<C: CodeComponent + Send + Sync + 'static>(mut self, component: C) -> Self {
        self.code = Some(Box::new(component));
        self
    }

    /// Set a custom blockquote component
    pub fn blockquote<C: BlockquoteComponent + Send + Sync + 'static>(
        mut self,
        component: C,
    ) -> Self {
        self.blockquote = Some(Box::new(component));
        self
    }

    /// Set a custom hard break component
    pub fn hard_break<C: HardBreakComponent + Send + Sync + 'static>(
        mut self,
        component: C,
    ) -> Self {
        self.hard_break = Some(Box::new(component));
        self
    }

    /// Set a custom horizontal rule component
    pub fn horizontal_rule<C: HorizontalRuleComponent + Send + Sync + 'static>(
        mut self,
        component: C,
    ) -> Self {
        self.horizontal_rule = Some(Box::new(component));
        self
    }

    /// Set a custom list component
    pub fn list<C: ListComponent + Send + Sync + 'static>(mut self, component: C) -> Self {
        self.list = Some(Box::new(component));
        self
    }

    /// Set a custom list item component
    pub fn list_item<C: ListItemComponent + Send + Sync + 'static>(mut self, component: C) -> Self {
        self.list_item = Some(Box::new(component));
        self
    }

    /// Set a custom strikethrough component
    pub fn strikethrough<C: StrikethroughComponent + Send + Sync + 'static>(
        mut self,
        component: C,
    ) -> Self {
        self.strikethrough = Some(Box::new(component));
        self
    }

    /// Set a custom task list marker component
    pub fn task_list_marker<C: TaskListMarkerComponent + Send + Sync + 'static>(
        mut self,
        component: C,
    ) -> Self {
        self.task_list_marker = Some(Box::new(component));
        self
    }

    /// Set a custom table component
    pub fn table<C: TableComponent + Send + Sync + 'static>(mut self, component: C) -> Self {
        self.table = Some(Box::new(component));
        self
    }

    /// Set a custom table head component
    pub fn table_head<C: TableHeadComponent + Send + Sync + 'static>(
        mut self,
        component: C,
    ) -> Self {
        self.table_head = Some(Box::new(component));
        self
    }

    /// Set a custom table row component
    pub fn table_row<C: TableRowComponent + Send + Sync + 'static>(mut self, component: C) -> Self {
        self.table_row = Some(Box::new(component));
        self
    }

    /// Set a custom table cell component
    pub fn table_cell<C: TableCellComponent + Send + Sync + 'static>(
        mut self,
        component: C,
    ) -> Self {
        self.table_cell = Some(Box::new(component));
        self
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::content::{MarkdownOptions, render_markdown};

    struct TestCustomHeading;

    impl HeadingComponent for TestCustomHeading {
        fn render_start(&self, level: u8, id: Option<&str>, classes: &[&str]) -> String {
            let id_attr = id.map(|i| format!(" id=\"{}\"", i)).unwrap_or_default();
            let class_attr = if classes.is_empty() {
                String::new()
            } else {
                format!(" class=\"{}\"", classes.join(" "))
            };
            format!("<h{}{}{}>🎯", level, id_attr, class_attr)
        }

        fn render_end(&self, level: u8) -> String {
            format!("</h{}>", level)
        }
    }

    struct TestCustomParagraph;

    impl ParagraphComponent for TestCustomParagraph {
        fn render_start(&self) -> String {
            "<p class=\"custom-paragraph\">".to_string()
        }

        fn render_end(&self) -> String {
            "</p><!-- end custom paragraph -->".to_string()
        }
    }

    struct TestCustomLink;

    impl LinkComponent for TestCustomLink {
        fn render_start(&self, url: &str, title: Option<&str>, _link_type: LinkType) -> String {
            let title_attr = title
                .map(|t| format!(" title=\"{}\"", t))
                .unwrap_or_default();
            format!("<a href=\"{}\" class=\"custom-link\"{}>🔗", url, title_attr)
        }

        fn render_end(&self) -> String {
            "</a>".to_string()
        }
    }

    struct TestCustomImage;

    impl ImageComponent for TestCustomImage {
        fn render(&self, url: &str, alt: &str, title: Option<&str>) -> String {
            let title_attr = title
                .map(|t| format!(" title=\"{}\"", t))
                .unwrap_or_default();
            format!(
                "<img src=\"{}\" alt=\"{}\" class=\"custom-image\"{} />📸",
                url, alt, title_attr
            )
        }
    }

    struct TestCustomStrong;

    impl StrongComponent for TestCustomStrong {
        fn render_start(&self) -> String {
            "<strong class=\"custom-strong\">💪".to_string()
        }

        fn render_end(&self) -> String {
            "</strong>".to_string()
        }
    }

    struct TestCustomEmphasis;

    impl EmphasisComponent for TestCustomEmphasis {
        fn render_start(&self) -> String {
            "<em class=\"custom-emphasis\">✨".to_string()
        }

        fn render_end(&self) -> String {
            "</em>".to_string()
        }
    }

    struct TestCustomCode;

    impl CodeComponent for TestCustomCode {
        fn render(&self, code: &str) -> String {
            format!("<code class=\"custom-code\">💻{}</code>", code)
        }
    }

    struct TestCustomBlockquote;

    impl BlockquoteComponent for TestCustomBlockquote {
        fn render_start(&self, kind: Option<BlockQuoteKind>) -> String {
            match kind {
                Some(k) => format!(
                    "<blockquote class=\"custom-blockquote {}\" data-kind=\"{}\">📝",
                    k.as_str(),
                    k.as_str()
                ),
                None => "<blockquote class=\"custom-blockquote\">📝".to_string(),
            }
        }

        fn render_end(&self, _kind: Option<BlockQuoteKind>) -> String {
            "</blockquote>".to_string()
        }
    }

    #[test]
    fn test_components_builder_pattern() {
        let components = MarkdownComponents::new().heading(TestCustomHeading);

        assert!(components.heading.is_some());
        assert!(components.paragraph.is_none());
        assert!(components.link.is_none());
    }

    #[test]
    fn test_has_any_components() {
        let empty_components = MarkdownComponents::new();
        assert!(!empty_components.has_any_components());

        let with_heading = MarkdownComponents::new().heading(TestCustomHeading);
        assert!(with_heading.has_any_components());
    }

    #[test]
    fn test_custom_heading_component() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new().heading(TestCustomHeading),
            ..Default::default()
        };

        let html = render_markdown("# Hello, world!", Some(&options), None, None);
        assert!(html.contains("🎯Hello, world!"));
    }

    #[test]
    fn test_custom_paragraph_component() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new().paragraph(TestCustomParagraph),
            ..Default::default()
        };

        let content = render_markdown("This is a paragraph.", Some(&options), None, None);
        assert!(content.contains(
            "<p class=\"custom-paragraph\">This is a paragraph.</p><!-- end custom paragraph -->"
        ));
    }

    #[test]
    fn test_custom_link_component() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new().link(TestCustomLink),
            ..Default::default()
        };

        let content = render_markdown("[Example](https://example.com)", Some(&options), None, None);
        assert!(
            content.contains("<a href=\"https://example.com\" class=\"custom-link\">🔗Example</a>")
        );
    }

    #[test]
    fn test_custom_image_component() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new().image(TestCustomImage),
            ..Default::default()
        };

        let content = render_markdown("![Alt text](image.jpg)", Some(&options), None, None);
        assert!(
            content.contains("<img src=\"image.jpg\" alt=\"Alt text\" class=\"custom-image\" />📸")
        );
    }

    #[test]
    fn test_custom_strong_component() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new().strong(TestCustomStrong),
            ..Default::default()
        };

        let content = render_markdown("**Bold text**", Some(&options), None, None);
        assert!(content.contains("<strong class=\"custom-strong\">💪Bold text</strong>"));
    }

    #[test]
    fn test_custom_emphasis_component() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new().emphasis(TestCustomEmphasis),
            ..Default::default()
        };

        let content = render_markdown("*Italic text*", Some(&options), None, None);
        assert!(content.contains("<em class=\"custom-emphasis\">✨Italic text</em>"));
    }

    #[test]
    fn test_custom_code_component() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new().code(TestCustomCode),
            ..Default::default()
        };

        let content = render_markdown("`console.log('hello')`", Some(&options), None, None);
        assert!(content.contains("<code class=\"custom-code\">💻console.log('hello')</code>"));
    }

    #[test]
    fn test_custom_blockquote_component() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new().blockquote(TestCustomBlockquote),
            ..Default::default()
        };

        let content = render_markdown("> This is a quote", Some(&options), None, None);
        assert!(content.contains("<blockquote class=\"custom-blockquote\">📝"));
        assert!(content.contains("</blockquote>"));
        assert!(content.contains("This is a quote"));
    }

    #[test]
    fn test_multiple_custom_components() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new()
                .heading(TestCustomHeading)
                .paragraph(TestCustomParagraph)
                .link(TestCustomLink)
                .strong(TestCustomStrong),
            ..Default::default()
        };

        let content = render_markdown(
            "# Title\n\nThis is a **bold** [link](https://example.com).",
            Some(&options),
            None,
            None,
        );

        assert!(content.contains("🎯Title"));
        assert!(content.contains("<p class=\"custom-paragraph\">"));
        assert!(content.contains("<strong class=\"custom-strong\">💪bold</strong>"));
        assert!(
            content.contains("<a href=\"https://example.com\" class=\"custom-link\">🔗link</a>")
        );
    }

    #[test]
    fn test_nested_components() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new()
                .blockquote(TestCustomBlockquote)
                .strong(TestCustomStrong)
                .emphasis(TestCustomEmphasis)
                .code(TestCustomCode),
            ..Default::default()
        };

        let content = render_markdown(
            "> This is a **bold** and *italic* with `code`",
            Some(&options),
            None,
            None,
        );
        assert!(content.contains("<blockquote class=\"custom-blockquote\">📝"));
        assert!(content.contains("<strong class=\"custom-strong\">💪bold</strong>"));
        assert!(content.contains("<em class=\"custom-emphasis\">✨italic</em>"));
        assert!(content.contains("<code class=\"custom-code\">💻code</code>"));
        assert!(content.contains("</blockquote>"));
    }

    struct TestHardBreak;
    impl HardBreakComponent for TestHardBreak {
        fn render(&self) -> String {
            "<br class=\"custom-break\" />".to_string()
        }
    }

    struct TestHorizontalRule;
    impl HorizontalRuleComponent for TestHorizontalRule {
        fn render(&self) -> String {
            "<hr class=\"custom-rule\" />".to_string()
        }
    }

    struct TestList;
    impl ListComponent for TestList {
        fn render_start(&self, list_type: ListType, start_number: Option<u64>) -> String {
            match list_type {
                ListType::Ordered => format!(
                    "<ol class=\"custom-list\" start=\"{}\">",
                    start_number.unwrap_or(1)
                ),
                ListType::Unordered => "<ul class=\"custom-list\">".to_string(),
            }
        }
        fn render_end(&self, list_type: ListType) -> String {
            match list_type {
                ListType::Ordered => "</ol>".to_string(),
                ListType::Unordered => "</ul>".to_string(),
            }
        }
    }

    struct TestListItem;
    impl ListItemComponent for TestListItem {
        fn render_start(&self) -> String {
            "<li class=\"custom-item\">".to_string()
        }
        fn render_end(&self) -> String {
            "</li>".to_string()
        }
    }

    struct TestStrikethrough;
    impl StrikethroughComponent for TestStrikethrough {
        fn render_start(&self) -> String {
            "<del class=\"custom-strike\">".to_string()
        }
        fn render_end(&self) -> String {
            "</del>".to_string()
        }
    }

    struct TestTaskListMarker;
    impl TaskListMarkerComponent for TestTaskListMarker {
        fn render(&self, checked: bool) -> String {
            if checked {
                "<input type=\"checkbox\" checked class=\"custom-task\" />"
            } else {
                "<input type=\"checkbox\" class=\"custom-task\" />"
            }
            .to_string()
        }
    }

    struct TestTable;
    impl TableComponent for TestTable {
        fn render_start(&self, _alignments: &[TableAlignment]) -> String {
            "<table class=\"custom-table\">".to_string()
        }
        fn render_end(&self) -> String {
            "</table>".to_string()
        }
    }

    struct TestTableHead;
    impl TableHeadComponent for TestTableHead {
        fn render_start(&self) -> String {
            "<thead class=\"custom-thead\">".to_string()
        }
        fn render_end(&self) -> String {
            "</thead>".to_string()
        }
    }

    struct TestTableRow;
    impl TableRowComponent for TestTableRow {
        fn render_start(&self) -> String {
            "<tr class=\"custom-row\">".to_string()
        }
        fn render_end(&self) -> String {
            "</tr>".to_string()
        }
    }

    struct TestTableCell;
    impl TableCellComponent for TestTableCell {
        fn render_start(&self, is_header: bool, alignment: Option<TableAlignment>) -> String {
            let tag = if is_header { "th" } else { "td" };
            let align = match alignment {
                Some(TableAlignment::Left) => " style=\"text-align: left\"",
                Some(TableAlignment::Center) => " style=\"text-align: center\"",
                Some(TableAlignment::Right) => " style=\"text-align: right\"",
                None => "",
            };
            format!("<{} class=\"custom-cell\"{}>", tag, align)
        }
        fn render_end(&self, is_header: bool) -> String {
            if is_header {
                "</th>".to_string()
            } else {
                "</td>".to_string()
            }
        }
    }

    #[test]
    fn test_hard_break_component() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new().hard_break(TestHardBreak),
            ..Default::default()
        };
        let content = render_markdown("Line 1  \nLine 2", Some(&options), None, None);
        assert!(content.contains("<br class=\"custom-break\" />"));
    }

    #[test]
    fn test_horizontal_rule_component() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new().horizontal_rule(TestHorizontalRule),
            ..Default::default()
        };
        let content = render_markdown("---", Some(&options), None, None);
        assert!(content.contains("<hr class=\"custom-rule\" />"));
    }

    #[test]
    fn test_list_components() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new()
                .list(TestList)
                .list_item(TestListItem),
            ..Default::default()
        };
        let content = render_markdown(
            "1. First\n2. Second\n\n- Bullet\n- Point",
            Some(&options),
            None,
            None,
        );
        assert!(content.contains("<ol class=\"custom-list\" start=\"1\">"));
        assert!(content.contains("<ul class=\"custom-list\">"));
        assert!(content.contains("<li class=\"custom-item\">"));
    }

    #[test]
    fn test_strikethrough_component() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new().strikethrough(TestStrikethrough),
            ..Default::default()
        };
        let content = render_markdown("~~strikethrough~~", Some(&options), None, None);
        assert!(content.contains("<del class=\"custom-strike\">"));
    }

    #[test]
    fn test_task_list_component() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new().task_list_marker(TestTaskListMarker),
            ..Default::default()
        };
        let content = render_markdown("- [x] Done\n- [ ] Todo", Some(&options), None, None);
        assert!(content.contains("<input type=\"checkbox\" checked class=\"custom-task\" />"));
        assert!(content.contains("<input type=\"checkbox\" class=\"custom-task\" />"));
    }

    #[test]
    fn test_table_components() {
        let options = MarkdownOptions {
            components: MarkdownComponents::new()
                .table(TestTable)
                .table_head(TestTableHead)
                .table_row(TestTableRow)
                .table_cell(TestTableCell),
            ..Default::default()
        };
        let content = render_markdown(
            "| Header | Header |\n|--------|--------|\n| Cell   | Cell   |",
            Some(&options),
            None,
            None,
        );
        assert!(content.contains("<table class=\"custom-table\">"));
        assert!(content.contains("<thead class=\"custom-thead\">"));
        assert!(content.contains("<tr class=\"custom-row\">"));
        assert!(content.contains("<td class=\"custom-cell\">"));
    }
}