@@ -552,4 +552,140 @@ describe('toc', () => {
552
552
553
553
toc ( html , { class : 'foo' , class_child : 'bar' } ) . should . eql ( expected ) ;
554
554
} ) ;
555
+
556
+ it ( 'max_items - result contains only h1 items' , ( ) => {
557
+ const className = 'toc' ;
558
+ const expected = [
559
+ '<ol class="' + className + '">' ,
560
+ '<li class="' + className + '-item ' + className + '-level-1">' ,
561
+ '<a class="' + className + '-link" href="#title_1">' ,
562
+ '<span class="' + className + '-number">1.</span> ' , // list_number enabled
563
+ '<span class="' + className + '-text">Title 1</span>' ,
564
+ '</a>' ,
565
+ // '<ol class="' + className + '-child">',
566
+ // <!-- h2 is truncated -->
567
+ // '</ol>',
568
+ '</li>' ,
569
+ '<li class="' + className + '-item ' + className + '-level-1">' ,
570
+ '<a class="' + className + '-link" href="#title_2">' ,
571
+ '<span class="' + className + '-number">2.</span> ' , // list_number enabled
572
+ '<span class="' + className + '-text">Title 2</span>' ,
573
+ '</a>' ,
574
+ // '<ol class="' + className + '-child">',
575
+ // <!-- h2 is truncated -->
576
+ // '</ol>',
577
+ '</li>' ,
578
+ '<li class="' + className + '-item ' + className + '-level-1">' ,
579
+ '<a class="' + className + '-link" href="#title_3">' ,
580
+ '<span class="' + className + '-number">3.</span> ' , // list_number enabled
581
+ '<span class="' + className + '-text">Title should escape &, <, ', and "</span>' ,
582
+ '</a>' ,
583
+ '</li>' ,
584
+ '<li class="' + className + '-item ' + className + '-level-1">' ,
585
+ '<a class="' + className + '-link" href="#title_4">' ,
586
+ '<span class="' + className + '-number">4.</span> ' , // list_number enabled
587
+ '<span class="' + className + '-text">Chapter 1 should be printed to toc</span>' ,
588
+ '</a>' ,
589
+ '</li>' ,
590
+ '</ol>'
591
+ ] . join ( '' ) ;
592
+
593
+ toc ( html , { max_items : 4 } ) . should . eql ( expected ) ; // The number of `h1` is 4
594
+ toc ( html , { max_items : 7 } ) . should . eql ( expected ) ; // Maximum number 7 cannot display up to `h2`
595
+ } ) ;
596
+
597
+ it ( 'max_items - result contains h1 and h2 items' , ( ) => {
598
+ const className = 'toc' ;
599
+ const expected = [
600
+ '<ol class="' + className + '">' ,
601
+ '<li class="' + className + '-item ' + className + '-level-1">' ,
602
+ '<a class="' + className + '-link" href="#title_1">' ,
603
+ '<span class="' + className + '-number">1.</span> ' , // list_number enabled
604
+ '<span class="' + className + '-text">Title 1</span>' ,
605
+ '</a>' ,
606
+ '<ol class="' + className + '-child">' ,
607
+ '<li class="' + className + '-item ' + className + '-level-2">' ,
608
+ '<a class="' + className + '-link" href="#title_1_1">' ,
609
+ '<span class="' + className + '-number">1.1.</span> ' , // list_number enabled
610
+ '<span class="' + className + '-text">Title 1.1</span>' ,
611
+ '</a>' ,
612
+ // '<ol class="' + className + '-child">',
613
+ // <!-- h3 is truncated -->
614
+ // '</ol>',
615
+ '</li>' ,
616
+ '<li class="' + className + '-item ' + className + '-level-2">' ,
617
+ '<a class="' + className + '-link" href="#title_1_2">' ,
618
+ '<span class="' + className + '-number">1.2.</span> ' , // list_number enabled
619
+ '<span class="' + className + '-text">Title 1.2</span>' ,
620
+ '</a>' ,
621
+ '</li>' ,
622
+ '<li class="' + className + '-item ' + className + '-level-2">' ,
623
+ '<a class="' + className + '-link" href="#title_1_3">' ,
624
+ '<span class="' + className + '-number">1.3.</span> ' , // list_number enabled
625
+ '<span class="' + className + '-text">Title 1.3</span>' ,
626
+ '</a>' ,
627
+ // '<ol class="' + className + '-child">',
628
+ // <!-- h3 is truncated -->
629
+ // '</ol>',
630
+ '</li>' ,
631
+ '</ol>' ,
632
+ '</li>' ,
633
+ '<li class="' + className + '-item ' + className + '-level-1">' ,
634
+ '<a class="' + className + '-link" href="#title_2">' ,
635
+ '<span class="' + className + '-number">2.</span> ' , // list_number enabled
636
+ '<span class="' + className + '-text">Title 2</span>' ,
637
+ '</a>' ,
638
+ '<ol class="' + className + '-child">' ,
639
+ '<li class="' + className + '-item ' + className + '-level-2">' ,
640
+ '<a class="' + className + '-link" href="#title_2_1">' ,
641
+ '<span class="' + className + '-number">2.1.</span> ' , // list_number enabled
642
+ '<span class="' + className + '-text">Title 2.1</span>' ,
643
+ '</a>' ,
644
+ '</li>' ,
645
+ '</ol>' ,
646
+ '</li>' ,
647
+ '<li class="' + className + '-item ' + className + '-level-1">' ,
648
+ '<a class="' + className + '-link" href="#title_3">' ,
649
+ '<span class="' + className + '-number">3.</span> ' , // list_number enabled
650
+ '<span class="' + className + '-text">Title should escape &, <, ', and "</span>' ,
651
+ '</a>' ,
652
+ '</li>' ,
653
+ '<li class="' + className + '-item ' + className + '-level-1">' ,
654
+ '<a class="' + className + '-link" href="#title_4">' ,
655
+ '<span class="' + className + '-number">4.</span> ' , // list_number enabled
656
+ '<span class="' + className + '-text">Chapter 1 should be printed to toc</span>' ,
657
+ '</a>' ,
658
+ '</li>' ,
659
+ '</ol>'
660
+ ] . join ( '' ) ;
661
+
662
+ toc ( html , { max_items : 8 } ) . should . eql ( expected ) ; // Maximum number 8 can display up to `h2`
663
+ toc ( html , { max_items : 9 } ) . should . eql ( expected ) ; // Maximum number 10 is required to display up to `h3`
664
+ } ) ;
665
+
666
+ it ( 'max_items - result of h1 was truncated' , ( ) => {
667
+ const className = 'toc' ;
668
+ const expected = [
669
+ '<ol class="' + className + '">' ,
670
+ '<li class="' + className + '-item ' + className + '-level-1">' ,
671
+ '<a class="' + className + '-link" href="#title_1">' ,
672
+ '<span class="' + className + '-number">1.</span> ' , // list_number enabled
673
+ '<span class="' + className + '-text">Title 1</span>' ,
674
+ '</a>' ,
675
+ // '<ol class="' + className + '-child">',
676
+ // <!-- h2 is truncated -->
677
+ // '</ol>',
678
+ '</li>' ,
679
+ '<li class="' + className + '-item ' + className + '-level-1">' ,
680
+ '<a class="' + className + '-link" href="#title_2">' ,
681
+ '<span class="' + className + '-number">2.</span> ' , // list_number enabled
682
+ '<span class="' + className + '-text">Title 2</span>' ,
683
+ '</a>' ,
684
+ '</li>' ,
685
+ // <!-- `h1` is truncated from the end -->
686
+ '</ol>'
687
+ ] . join ( '' ) ;
688
+
689
+ toc ( html , { max_items : 2 } ) . should . eql ( expected ) ; // `h1` is truncated from the end
690
+ } ) ;
555
691
} ) ;
0 commit comments