Debian Codegraph @

tests/test_extensions/test_blocks/test_captions.py

raw
1 """Test cases for Blocks (caption)."""
2 from ... import util
3
4
5 class TestBlocksCaption(util.MdCase):
6 """Test Blocks caption cases with default configuration."""
7
8 extension = ['pymdownx.blocks.caption', 'md_in_html', 'pymdownx.blocks.html']
9 extension_configs = {
10 'pymdownx.blocks.caption': {
11 'auto': False
12 }
13 }
14
15 def test_caption(self):
16 """Test basic caption."""
17
18 self.check_markdown(
19 R'''
20 A paragraph with a caption.
21 /// caption
22 This is the caption.
23 ///
24 ''',
25 R'''
26 <figure>
27 <p>A paragraph with a caption.</p>
28 <figcaption>
29 <p>This is the caption.</p>
30 </figcaption>
31 </figure>
32 ''',
33 True
34 )
35
36 def test_caption_with_markdown(self):
37 """Test caption with markdown."""
38
39 self.check_markdown(
40 R'''
41 A paragraph with a caption.
42 /// caption
43 This is the **caption**.
44 ///
45 ''',
46 R'''
47 <figure>
48 <p>A paragraph with a caption.</p>
49 <figcaption>
50 <p>This is the <strong>caption</strong>.</p>
51 </figcaption>
52 </figure>
53 ''',
54 True
55 )
56
57 def test_image_caption(self):
58 """Test image caption."""
59
60 self.check_markdown(
61 R'''
62 ![Alt text](/path/to/img.jpg)
63 /// caption
64 This is the caption.
65 ///
66 ''',
67 R'''
68 <figure>
69 <p><img alt="Alt text" src="/path/to/img.jpg" /></p>
70 <figcaption>
71 <p>This is the caption.</p>
72 </figcaption>
73 </figure>
74 ''',
75 True
76 )
77
78 def test_nested_caption(self):
79 """Test nested caption."""
80
81 self.check_markdown(
82 R'''
83 A paragraph with a caption.
84 /// caption
85 This is the nested caption.
86 ///
87 /// caption
88 This is the caption.
89 ///
90 ''',
91 R'''
92 <figure>
93 <figure>
94 <p>A paragraph with a caption.</p>
95 <figcaption>
96 <p>This is the nested caption.</p>
97 </figcaption>
98 </figure>
99 <figcaption>
100 <p>This is the caption.</p>
101 </figcaption>
102 </figure>
103 ''',
104 True
105 )
106
107 def test_caption_in_figure_block(self):
108 """Test that captions are injected into existing figures."""
109
110 self.check_markdown(
111 R"""
112 <figure markdown>
113 Some content
114 </figure>
115 /// caption
116 Caption.
117 ///
118
119 /// html | figure
120 Some content
121 ///
122 /// caption
123 Caption.
124 ///
125 """,
126 """
127 <figure>
128 <p>Some content</p>
129 <figcaption>
130 <p>Caption.</p>
131 </figcaption>
132 </figure>
133 <figure>
134 <p>Some content</p>
135 <figcaption>
136 <p>Caption.</p>
137 </figcaption>
138 </figure>
139 """,
140 True
141 )
142
143 def test_caption_not_in_figure_block(self):
144 """Test that captions are not injected into existing figures that already have captions."""
145
146 self.check_markdown(
147 R"""
148 <figure markdown>
149 Some content
150
151 <figcaption markdown>
152 Existing caption
153 </figcaption>
154
155 </figure>
156 /// caption
157 Caption.
158 ///
159
160 /// html | figure
161 Some content
162 //// html | figcaption
163 Existing caption
164 ////
165 ///
166 /// caption
167 Caption.
168 ///
169 """,
170 R"""
171 <figure>
172 <figure>
173 <p>Some content</p>
174 <figcaption>
175 <p>Existing caption</p>
176 </figcaption>
177 </figure>
178 <figcaption>
179 <p>Caption.</p>
180 </figcaption>
181 </figure>
182 <figure>
183 <figure>
184 <p>Some content</p>
185 <figcaption>
186 <p>Existing caption</p>
187 </figcaption>
188 </figure>
189 <figcaption>
190 <p>Caption.</p>
191 </figcaption>
192 </figure>
193 """,
194 True
195 )
196
197 def test_manual_prepend(self):
198 """Test manual prepend."""
199
200 self.check_markdown(
201 R"""
202 Text
203 /// caption | <
204 Prepended
205 ///
206
207 Text
208 /// caption | >
209 Appended
210 ///
211 """,
212 R"""
213 <figure>
214 <figcaption>
215 <p>Prepended</p>
216 </figcaption>
217 <p>Text</p>
218 </figure>
219 <figure>
220 <p>Text</p>
221 <figcaption>
222 <p>Appended</p>
223 </figcaption>
224 </figure>
225 """,
226 True
227 )
228
229 def test_caption_inline_id(self):
230 """Test caption with inline shorthand ID."""
231
232 self.check_markdown(
233 R'''
234 Paragraph
235 /// figure-caption | #custom-id
236 Caption text.
237 ///
238 ''',
239 R'''
240 <figure id="custom-id">
241 <p>Paragraph</p>
242 <figcaption>
243 <p>Caption text.</p>
244 </figcaption>
245 </figure>
246 ''',
247 True
248 )
249
250 def test_caption_inline_id_prepend(self):
251 """Test caption with inline shorthand ID and prepend marker."""
252
253 self.check_markdown(
254 R'''
255 Text
256 /// figure-caption | < #custom-prepend
257 Prepended caption.
258 ///
259 ''',
260 R'''
261 <figure id="custom-prepend">
262 <figcaption>
263 <p>Prepended caption.</p>
264 </figcaption>
265 <p>Text</p>
266 </figure>
267 ''',
268 True
269 )
270
271 def test_caption_inline_id_with_extra_token(self):
272 """Ensure inline shorthand ID with extra tokens is rejected."""
273
274 self.check_markdown(
275 R"""
276 Paragraph
277 /// figure-caption | #custom-id extra
278 Caption text.
279 ///
280 """,
281 """
282 <p>Paragraph
283 /// figure-caption | #custom-id extra
284 Caption text.
285 ///</p>
286 """,
287 True
288 )
289
290 def test_caption_inline_id_invalid_identifier(self):
291 """Ensure inline shorthand ID with invalid characters is rejected."""
292
293 self.check_markdown(
294 R"""
295 Paragraph
296 /// figure-caption | #invalid!
297 Caption text.
298 ///
299 """,
300 """
301 <p>Paragraph
302 /// figure-caption | #invalid!
303 Caption text.
304 ///</p>
305 """,
306 True
307 )
308
309 def test_table_caption_inline_id(self):
310 """Test table caption with inline shorthand ID."""
311
312 self.check_markdown(
313 R'''
314 Paragraph
315 /// table-caption | #custom-table
316 Table caption text.
317 ///
318 ''',
319 R'''
320 <figure id="custom-table">
321 <p>Paragraph</p>
322 <figcaption>
323 <p>Table caption text.</p>
324 </figcaption>
325 </figure>
326 ''',
327 True
328 )
329
330 def test_caption_inline_id_attribute_override(self):
331 """Ensure inline shorthand ID does not override attribute-defined ID."""
332
333 self.check_markdown(
334 R'''
335 Paragraph
336 /// figure-caption | #inline-id
337 attrs: {id: attribute-id}
338 Caption text.
339 ///
340 ''',
341 R'''
342 <figure id="attribute-id">
343 <p>Paragraph</p>
344 <figcaption>
345 <p>Caption text.</p>
346 </figcaption>
347 </figure>
348 ''',
349 True
350 )
351
352 def test_bad_header(self):
353 """Test a bad header."""
354
355 self.check_markdown(
356 R"""
357 Test
358 /// caption | bad
359 ///
360 """,
361 """
362 <p>Test
363 /// caption | bad
364 ///</p>
365 """,
366 True
367 )
368
369 def test_table_caption_multiple_inline_id_not_allowed(self):
370 """Ensure multiple inline shorthand IDs are rejected."""
371
372 self.check_markdown(
373 R"""
374 Paragraph
375 /// table-caption | #id1#id2
376 Table caption text.
377 ///
378 """,
379 """
380 <p>Paragraph
381 /// table-caption | #id1#id2
382 Table caption text.
383 ///</p>
384 """,
385 True
386 )
387
388 def test_caption_inline_class_invalid_identifier(self):
389 """Ensure inline shorthand classes with invalid characters is rejected."""
390
391 self.check_markdown(
392 R"""
393 Paragraph
394 /// figure-caption | .invalid!
395 Caption text.
396 ///
397 """,
398 """
399 <p>Paragraph
400 /// figure-caption | .invalid!
401 Caption text.
402 ///</p>
403 """,
404 True
405 )
406
407 def test_caption_inline_class(self):
408 """Test caption with inline shorthand class."""
409
410 self.check_markdown(
411 R'''
412 Paragraph
413 /// figure-caption | .custom-class
414 Caption text.
415 ///
416 ''',
417 R'''
418 <figure class="custom-class">
419 <p>Paragraph</p>
420 <figcaption>
421 <p>Caption text.</p>
422 </figcaption>
423 </figure>
424 ''',
425 True
426 )
427
428 def test_caption_multiple_inline_class(self):
429 """Test caption with multiple inline shorthand class."""
430
431 self.check_markdown(
432 R'''
433 Paragraph
434 /// figure-caption | .custom-class1.custom-class2
435 Caption text.
436 ///
437 ''',
438 R'''
439 <figure class="custom-class1 custom-class2">
440 <p>Paragraph</p>
441 <figcaption>
442 <p>Caption text.</p>
443 </figcaption>
444 </figure>
445 ''',
446 True
447 )
448
449 def test_caption_inline_class_and_id(self):
450 """Test caption with inline shorthand class and id."""
451
452 self.check_markdown(
453 R'''
454 Paragraph
455 /// figure-caption | .custom-class#custom-id
456 Caption text.
457 ///
458 ''',
459 R'''
460 <figure class="custom-class" id="custom-id">
461 <p>Paragraph</p>
462 <figcaption>
463 <p>Caption text.</p>
464 </figcaption>
465 </figure>
466 ''',
467 True
468 )
469
470 def test_caption_inline_class_attribute_merge(self):
471 """Ensure inline shorthand class merges with attribute-defined class."""
472
473 self.check_markdown(
474 R'''
475 Paragraph
476 /// figure-caption | .inline-class
477 attrs: {class: attribute-class}
478 Caption text.
479 ///
480 ''',
481 R'''
482 <figure class="attribute-class inline-class">
483 <p>Paragraph</p>
484 <figcaption>
485 <p>Caption text.</p>
486 </figcaption>
487 </figure>
488 ''',
489 True
490 )
491
492 def test_caption_inline_class_unique(self):
493 """Ensure inline shorthand classes are unique."""
494
495 self.check_markdown(
496 R'''
497 Paragraph
498 /// figure-caption | .custom-class.custom-class
499 Caption text.
500 ///
501 ''',
502 R'''
503 <figure class="custom-class">
504 <p>Paragraph</p>
505 <figcaption>
506 <p>Caption text.</p>
507 </figcaption>
508 </figure>
509 ''',
510 True
511 )
512
513 def test_caption_inline_class_attribute_unique(self):
514 """Ensure inline shorthand classes and attribute classes are unique after merging."""
515
516 self.check_markdown(
517 R'''
518 Paragraph
519 /// figure-caption | .custom-class
520 attrs: {class: custom-class}
521 Caption text.
522 ///
523 ''',
524 R'''
525 <figure class="custom-class">
526 <p>Paragraph</p>
527 <figcaption>
528 <p>Caption text.</p>
529 </figcaption>
530 </figure>
531 ''',
532 True
533 )
534
535 def test_caption_inline_arbitrary_attribute(self):
536 """Ensure inline shorthand classes and attribute classes are unique after merging."""
537
538 self.check_markdown(
539 R'''
540 Paragraph
541 /// figure-caption | .custom-class[data="test"]
542 Caption text.
543 ///
544 ''',
545 R'''
546 <figure class="custom-class" data="test">
547 <p>Paragraph</p>
548 <figcaption>
549 <p>Caption text.</p>
550 </figcaption>
551 </figure>
552 ''',
553 True
554 )
555
556
557 class TestBlocksCaptionClass(util.MdCase):
558 """Test caption classes."""
559
560 extension = ['pymdownx.blocks.caption', 'md_in_html', 'pymdownx.blocks.html']
561 extension_configs = {
562 'pymdownx.blocks.caption': {
563 'types': [
564 {"name": "figure-class", "classes": "class1 class2"}
565 ]
566 }
567 }
568
569 def test_class_insertion(self):
570 """Test class insertion."""
571
572 self.check_markdown(
573 R'''
574 A paragraph with a caption.
575 /// figure-class
576 This is the caption.
577 ///
578 ''',
579 R'''
580 <figure class="class1 class2">
581 <p>A paragraph with a caption.</p>
582 <figcaption>
583 <p>This is the caption.</p>
584 </figcaption>
585 </figure>
586 ''',
587 True
588 )
589
590 def test_class_insertion_existing_figure(self):
591 """Test class insertion on existing figure."""
592
593 self.check_markdown(
594 R'''
595 /// html | figure
596 A paragraph with a caption.
597 ///
598 /// figure-class
599 This is the caption.
600 ///
601 ''',
602 R'''
603 <figure class="class1 class2">
604 <p>A paragraph with a caption.</p>
605 <figcaption>
606 <p>This is the caption.</p>
607 </figcaption>
608 </figure>
609 ''',
610 True
611 )
612
613 def test_class_insertion_existing_class(self):
614 """Test class insertion on existing figure with existing class."""
615
616 self.check_markdown(
617 R'''
618 /// html | figure.class1
619 A paragraph with a caption.
620 ///
621 /// figure-class
622 This is the caption.
623 ///
624 ''',
625 R'''
626 <figure class="class1 class2">
627 <p>A paragraph with a caption.</p>
628 <figcaption>
629 <p>This is the caption.</p>
630 </figcaption>
631 </figure>
632 ''',
633 True
634 )
635
636
637 class TestBlocksCaptionPrefix(util.MdCase):
638 """Test Blocks caption cases with enabled `auto`."""
639
640 extension = ['pymdownx.blocks.caption', 'md_in_html']
641 extension_configs = {
642 'pymdownx.blocks.caption': {
643 'auto': False
644 }
645 }
646
647 def test_caption(self):
648 """Test basic caption with `auto`."""
649
650 self.check_markdown(
651 R'''
652 A paragraph with a caption.
653 /// figure-caption | 1
654 This is the caption.
655 ///
656 ''',
657 R'''
658 <figure id="__figure-caption_1">
659 <p>A paragraph with a caption.</p>
660 <figcaption>
661 <p><span class="caption-prefix">Figure 1.</span> This is the caption.</p>
662 </figcaption>
663 </figure>
664 ''',
665 True
666 )
667
668 def test_consecutive_captions(self):
669 """Test consecutive captions with `auto`."""
670
671 self.check_markdown(
672 R'''
673 A paragraph with a caption.
674 /// figure-caption | 1
675 This is the caption.
676 ///
677
678 A paragraph with a caption.
679 /// figure-caption | 2
680 This is the caption.
681 ///
682 ''',
683 R'''
684 <figure id="__figure-caption_1">
685 <p>A paragraph with a caption.</p>
686 <figcaption>
687 <p><span class="caption-prefix">Figure 1.</span> This is the caption.</p>
688 </figcaption>
689 </figure>
690 <figure id="__figure-caption_2">
691 <p>A paragraph with a caption.</p>
692 <figcaption>
693 <p><span class="caption-prefix">Figure 2.</span> This is the caption.</p>
694 </figcaption>
695 </figure>
696 ''',
697 True
698 )
699
700 def test_nested_captions(self):
701 """Test nested captions with `auto`."""
702
703 self.check_markdown(
704 R'''
705 A paragraph with a caption.
706 /// figure-caption | 1.1.1
707 Level 3 caption.
708 ///
709 /// figure-caption | 1.1
710 Level 2 caption.
711 ///
712 /// figure-caption | 1
713 Level 1 caption.
714 ///
715 ''',
716 R'''
717 <figure id="__figure-caption_1">
718 <figure id="__figure-caption_1_1">
719 <figure id="__figure-caption_1_1_1">
720 <p>A paragraph with a caption.</p>
721 <figcaption>
722 <p><span class="caption-prefix">Figure 1.1.1.</span> Level 3 caption.</p>
723 </figcaption>
724 </figure>
725 <figcaption>
726 <p><span class="caption-prefix">Figure 1.1.</span> Level 2 caption.</p>
727 </figcaption>
728 </figure>
729 <figcaption>
730 <p><span class="caption-prefix">Figure 1.</span> Level 1 caption.</p>
731 </figcaption>
732 </figure>
733 ''',
734 True
735 )
736
737 def test_nested_consecutive_captions(self):
738 """Test nested captions with `auto`."""
739
740 self.check_markdown(
741 R'''
742 A paragraph with a caption.
743 /// figure-caption | 1.1.1
744 Level 3 caption.
745 ///
746 /// figure-caption | 1.1
747 Level 2 caption.
748 ///
749 /// figure-caption | 1
750 Level 1 caption.
751 ///
752
753 A paragraph with a caption.
754 /// figure-caption | 2.1
755 Level 2 caption.
756 ///
757 /// figure-caption | 2
758 Level 1 caption.
759 ///
760 ''',
761 R'''
762 <figure id="__figure-caption_1">
763 <figure id="__figure-caption_1_1">
764 <figure id="__figure-caption_1_1_1">
765 <p>A paragraph with a caption.</p>
766 <figcaption>
767 <p><span class="caption-prefix">Figure 1.1.1.</span> Level 3 caption.</p>
768 </figcaption>
769 </figure>
770 <figcaption>
771 <p><span class="caption-prefix">Figure 1.1.</span> Level 2 caption.</p>
772 </figcaption>
773 </figure>
774 <figcaption>
775 <p><span class="caption-prefix">Figure 1.</span> Level 1 caption.</p>
776 </figcaption>
777 </figure>
778 <figure id="__figure-caption_2">
779 <figure id="__figure-caption_2_1">
780 <p>A paragraph with a caption.</p>
781 <figcaption>
782 <p><span class="caption-prefix">Figure 2.1.</span> Level 2 caption.</p>
783 </figcaption>
784 </figure>
785 <figcaption>
786 <p><span class="caption-prefix">Figure 2.</span> Level 1 caption.</p>
787 </figcaption>
788 </figure>
789 ''',
790 True
791 )
792
793 def test_caption_inline_id(self):
794 """Test caption with inline shorthand ID."""
795
796 self.check_markdown(
797 R'''
798 Paragraph
799 /// figure-caption | #custom-id
800 Caption text.
801 ///
802 ''',
803 R'''
804 <figure id="custom-id">
805 <p>Paragraph</p>
806 <figcaption>
807 <p>Caption text.</p>
808 </figcaption>
809 </figure>
810 ''',
811 True
812 )
813
814 def test_caption_inline_id_prepend(self):
815 """Test caption with inline shorthand ID and prepend marker."""
816
817 self.check_markdown(
818 R'''
819 Text
820 /// figure-caption | < #custom-prepend
821 Prepended caption.
822 ///
823 ''',
824 R'''
825 <figure id="custom-prepend">
826 <figcaption>
827 <p>Prepended caption.</p>
828 </figcaption>
829 <p>Text</p>
830 </figure>
831 ''',
832 True
833 )
834
835 def test_inject_new_p_in_caption(self):
836 """Test `auto` cases that require the prefix to be injected in a new paragraph."""
837
838 self.check_markdown(
839 R"""
840 Test
841 /// figure-caption | 1
842 ///
843
844 Test
845 /// figure-caption | 2
846 > blockquote
847 ///
848 """,
849 R"""
850 <figure id="__figure-caption_1">
851 <p>Test</p>
852 <figcaption>
853 <p><span class="caption-prefix">Figure 1.</span></p>
854 </figcaption>
855 </figure>
856 <figure id="__figure-caption_2">
857 <p>Test</p>
858 <figcaption>
859 <p><span class="caption-prefix">Figure 2.</span></p>
860 <blockquote>
861 <p>blockquote</p>
862 </blockquote>
863 </figcaption>
864 </figure>
865 """,
866 True
867 )
868
869 def test_empty_paragraph(self):
870 """Test `auto` cases that require prefix to inject a new paragraph."""
871
872 self.check_markdown(
873 R"""
874 Test
875 /// figure-caption | 1
876 <p markdown></p>
877 ///
878 """,
879 R"""
880 <figure id="__figure-caption_1">
881 <p>Test</p>
882 <figcaption>
883 <p><span class="caption-prefix">Figure 1.</span></p>
884 </figcaption>
885 </figure>
886 """,
887 True
888 )
889
890 def test_manual_prepend(self):
891 """Test manual prepend."""
892
893 self.check_markdown(
894 R"""
895 Text
896 /// figure-caption | < 2
897 Prepended
898 ///
899
900 Text
901 /// figure-caption | > 5
902 Appended
903 ///
904 """,
905 R"""
906 <figure id="__figure-caption_2">
907 <figcaption>
908 <p><span class="caption-prefix">Figure 2.</span> Prepended</p>
909 </figcaption>
910 <p>Text</p>
911 </figure>
912 <figure id="__figure-caption_5">
913 <p>Text</p>
914 <figcaption>
915 <p><span class="caption-prefix">Figure 5.</span> Appended</p>
916 </figcaption>
917 </figure>
918 """,
919 True
920 )
921
922 def test_depth(self):
923 """Depth is not really supported in manual, so a generic response is expected."""
924
925 self.check_markdown(
926 R"""
927 Paragraph
928 /// figure-caption
929 Caption 1
930 ///
931
932 Paragraph
933 /// figure-caption | ^1
934 Caption 1.1
935 ///
936
937 Paragraph
938 /// figure-caption | ^2
939 Caption 1.1.1
940 ///
941
942 Paragraph
943 /// figure-caption | ^3
944 Caption 1.1.1.1
945 ///
946 """,
947 """
948 <figure>
949 <p>Paragraph</p>
950 <figcaption>
951 <p>Caption 1</p>
952 </figcaption>
953 </figure>
954 <figure id="__figure-caption_1_1">
955 <p>Paragraph</p>
956 <figcaption>
957 <p><span class="caption-prefix">Figure 1.1.</span> Caption 1.1</p>
958 </figcaption>
959 </figure>
960 <figure id="__figure-caption_1_1_1">
961 <p>Paragraph</p>
962 <figcaption>
963 <p><span class="caption-prefix">Figure 1.1.1.</span> Caption 1.1.1</p>
964 </figcaption>
965 </figure>
966 <figure id="__figure-caption_1_1_1_1">
967 <p>Paragraph</p>
968 <figcaption>
969 <p><span class="caption-prefix">Figure 1.1.1.1.</span> Caption 1.1.1.1</p>
970 </figcaption>
971 </figure>
972 """,
973 True
974 )
975
976
977 class TestBlocksCaptionAutoPrefix(util.MdCase):
978 """Test Blocks caption cases with enabled `auto`."""
979
980 extension = ['pymdownx.blocks.caption', 'md_in_html']
981 extension_configs = {
982 'pymdownx.blocks.caption': {
983 }
984 }
985
986 def test_caption_number_and_id(self):
987 """Test captions with IDs and number."""
988
989 self.check_markdown(
990 R'''
991 A paragraph with a caption.
992 /// figure-caption | 3 #id
993 This is the caption.
994 ///
995
996 A paragraph with a caption.
997 /// figure-caption | < 4 #id2
998 This is the caption.
999 ///
1000 ''',
1001 R'''
1002 <figure id="id">
1003 <p>A paragraph with a caption.</p>
1004 <figcaption>
1005 <p><span class="caption-prefix">Figure 3.</span> This is the caption.</p>
1006 </figcaption>
1007 </figure>
1008 <figure id="id2">
1009 <figcaption>
1010 <p><span class="caption-prefix">Figure 4.</span> This is the caption.</p>
1011 </figcaption>
1012 <p>A paragraph with a caption.</p>
1013 </figure>
1014 ''',
1015 True
1016 )
1017
1018 def test_caption(self):
1019 """Test basic caption with `auto`."""
1020
1021 self.check_markdown(
1022 R'''
1023 A paragraph with a caption.
1024 /// figure-caption
1025 This is the caption.
1026 ///
1027 ''',
1028 R'''
1029 <figure id="__figure-caption_1">
1030 <p>A paragraph with a caption.</p>
1031 <figcaption>
1032 <p><span class="caption-prefix">Figure 1.</span> This is the caption.</p>
1033 </figcaption>
1034 </figure>
1035 ''',
1036 True
1037 )
1038
1039 def test_consecutive_captions(self):
1040 """Test consecutive captions with `auto`."""
1041
1042 self.check_markdown(
1043 R'''
1044 A paragraph with a caption.
1045 /// figure-caption
1046 This is the caption.
1047 ///
1048
1049 A paragraph with a caption.
1050 /// figure-caption
1051 This is the caption.
1052 ///
1053 ''',
1054 R'''
1055 <figure id="__figure-caption_1">
1056 <p>A paragraph with a caption.</p>
1057 <figcaption>
1058 <p><span class="caption-prefix">Figure 1.</span> This is the caption.</p>
1059 </figcaption>
1060 </figure>
1061 <figure id="__figure-caption_2">
1062 <p>A paragraph with a caption.</p>
1063 <figcaption>
1064 <p><span class="caption-prefix">Figure 2.</span> This is the caption.</p>
1065 </figcaption>
1066 </figure>
1067 ''',
1068 True
1069 )
1070
1071 def test_nested_captions(self):
1072 """Test nested captions with `auto`."""
1073
1074 self.check_markdown(
1075 R'''
1076 A paragraph with a caption.
1077 /// figure-caption
1078 Level 3 caption.
1079 ///
1080 /// figure-caption
1081 Level 2 caption.
1082 ///
1083 /// figure-caption
1084 Level 1 caption.
1085 ///
1086 ''',
1087 R'''
1088 <figure id="__figure-caption_1">
1089 <figure id="__figure-caption_1_1">
1090 <figure id="__figure-caption_1_1_1">
1091 <p>A paragraph with a caption.</p>
1092 <figcaption>
1093 <p><span class="caption-prefix">Figure 1.1.1.</span> Level 3 caption.</p>
1094 </figcaption>
1095 </figure>
1096 <figcaption>
1097 <p><span class="caption-prefix">Figure 1.1.</span> Level 2 caption.</p>
1098 </figcaption>
1099 </figure>
1100 <figcaption>
1101 <p><span class="caption-prefix">Figure 1.</span> Level 1 caption.</p>
1102 </figcaption>
1103 </figure>
1104 ''',
1105 True
1106 )
1107
1108 def test_nested_consecutive_captions(self):
1109 """Test nested captions with `auto`."""
1110
1111 self.check_markdown(
1112 R'''
1113 A paragraph with a caption.
1114 /// figure-caption
1115 Level 3 caption.
1116 ///
1117 /// figure-caption
1118 Level 2 caption.
1119 ///
1120 /// figure-caption
1121 Level 1 caption.
1122 ///
1123
1124 A paragraph with a caption.
1125 /// figure-caption
1126 Level 2 caption.
1127 ///
1128 /// figure-caption
1129 Level 1 caption.
1130 ///
1131 ''',
1132 R'''
1133 <figure id="__figure-caption_1">
1134 <figure id="__figure-caption_1_1">
1135 <figure id="__figure-caption_1_1_1">
1136 <p>A paragraph with a caption.</p>
1137 <figcaption>
1138 <p><span class="caption-prefix">Figure 1.1.1.</span> Level 3 caption.</p>
1139 </figcaption>
1140 </figure>
1141 <figcaption>
1142 <p><span class="caption-prefix">Figure 1.1.</span> Level 2 caption.</p>
1143 </figcaption>
1144 </figure>
1145 <figcaption>
1146 <p><span class="caption-prefix">Figure 1.</span> Level 1 caption.</p>
1147 </figcaption>
1148 </figure>
1149 <figure id="__figure-caption_2">
1150 <figure id="__figure-caption_2_1">
1151 <p>A paragraph with a caption.</p>
1152 <figcaption>
1153 <p><span class="caption-prefix">Figure 2.1.</span> Level 2 caption.</p>
1154 </figcaption>
1155 </figure>
1156 <figcaption>
1157 <p><span class="caption-prefix">Figure 2.</span> Level 1 caption.</p>
1158 </figcaption>
1159 </figure>
1160 ''',
1161 True
1162 )
1163
1164 def test_manual_prepend(self):
1165 """Test manual prepend."""
1166
1167 self.check_markdown(
1168 R"""
1169 Text
1170 /// figure-caption | < 2
1171 Prepended and number ignored
1172 ///
1173
1174 Text
1175 /// figure-caption | >
1176 Appended
1177 ///
1178 """,
1179 R"""
1180 <figure id="__figure-caption_2">
1181 <figcaption>
1182 <p><span class="caption-prefix">Figure 2.</span> Prepended and number ignored</p>
1183 </figcaption>
1184 <p>Text</p>
1185 </figure>
1186 <figure id="__figure-caption_3">
1187 <p>Text</p>
1188 <figcaption>
1189 <p><span class="caption-prefix">Figure 3.</span> Appended</p>
1190 </figcaption>
1191 </figure>
1192 """,
1193 True
1194 )
1195
1196 def test_mixed_captions(self):
1197 """Test mixed captions with `auto`."""
1198
1199 self.check_markdown(
1200 R'''
1201 Paragraph
1202 /// caption
1203 Not numbered
1204 ///
1205
1206 Paragraph
1207 /// figure-caption
1208 Numbered level 2 caption.
1209 ///
1210 /// caption
1211 Not numbered level 1.
1212 ///
1213 /// figure-caption
1214 Numbered level 1 caption.
1215 ///
1216 ''',
1217 R'''
1218 <figure>
1219 <p>Paragraph</p>
1220 <figcaption>
1221 <p>Not numbered</p>
1222 </figcaption>
1223 </figure>
1224 <figure id="__figure-caption_1">
1225 <figure>
1226 <figure id="__figure-caption_1_1">
1227 <p>Paragraph</p>
1228 <figcaption>
1229 <p><span class="caption-prefix">Figure 1.1.</span> Numbered level 2 caption.</p>
1230 </figcaption>
1231 </figure>
1232 <figcaption>
1233 <p>Not numbered level 1.</p>
1234 </figcaption>
1235 </figure>
1236 <figcaption>
1237 <p><span class="caption-prefix">Figure 1.</span> Numbered level 1 caption.</p>
1238 </figcaption>
1239 </figure>
1240 ''',
1241 True
1242 )
1243
1244 def test_existing_fig_caption(self):
1245 """Test when a figure has a figure caption and we don't know what type it is."""
1246
1247 self.check_markdown(
1248 R"""
1249 <figure markdown>
1250 Some text.
1251 <figcaption markdown>
1252 Caption.
1253 </figcaption>
1254 </figure>
1255 """,
1256 R"""
1257 <figure>
1258 <p>Some text.</p>
1259 <figcaption>
1260 <p>Caption.</p>
1261 </figcaption>
1262 </figure>
1263 """,
1264 True
1265 )
1266
1267 def test_inject_new_p_in_caption(self):
1268 """Test `auto` cases that require the prefix to be injected in a new paragraph."""
1269
1270 self.check_markdown(
1271 R"""
1272 Test
1273 /// figure-caption
1274 ///
1275
1276 Test
1277 /// figure-caption
1278 > blockquote
1279 ///
1280 """,
1281 R"""
1282 <figure id="__figure-caption_1">
1283 <p>Test</p>
1284 <figcaption><p><span class="caption-prefix">Figure 1.</span></p></figcaption>
1285 </figure>
1286 <figure id="__figure-caption_2">
1287 <p>Test</p>
1288 <figcaption><p><span class="caption-prefix">Figure 2.</span></p>
1289 <blockquote>
1290 <p>blockquote</p>
1291 </blockquote>
1292 </figcaption>
1293 </figure>
1294 """,
1295 True
1296 )
1297
1298 def test_empty_paragraph(self):
1299 """Test `auto` cases that require prefix to inject a new paragraph."""
1300
1301 self.check_markdown(
1302 R"""
1303 Test
1304 /// figure-caption
1305 <p markdown></p>
1306 ///
1307 """,
1308 R"""
1309 <figure id="__figure-caption_1">
1310 <p>Test</p>
1311 <figcaption>
1312 <p><span class="caption-prefix">Figure 1.</span></p>
1313 </figcaption>
1314 </figure>
1315 """,
1316 True
1317 )
1318
1319 def test_nested_captions_manual_id(self):
1320 """Test nested captions with `auto` and `auto` with manual IDs."""
1321
1322 self.check_markdown(
1323 R'''
1324 A paragraph with a caption.
1325 /// figure-caption
1326 Level 4 caption.
1327 ///
1328 /// figure-caption
1329 attrs: {id: test}
1330 Level 3 caption.
1331 ///
1332 /// figure-caption
1333 Level 2 caption.
1334 ///
1335 /// figure-caption
1336 Level 1 caption.
1337 ///
1338 ''',
1339 R'''
1340 <figure id="__figure-caption_1">
1341 <figure id="__figure-caption_1_1">
1342 <figure id="test">
1343 <figure id="__figure-caption_1_1_1_1">
1344 <p>A paragraph with a caption.</p>
1345 <figcaption>
1346 <p><span class="caption-prefix">Figure 1.1.1.1.</span> Level 4 caption.</p>
1347 </figcaption>
1348 </figure>
1349 <figcaption>
1350 <p><span class="caption-prefix">Figure 1.1.1.</span> Level 3 caption.</p>
1351 </figcaption>
1352 </figure>
1353 <figcaption>
1354 <p><span class="caption-prefix">Figure 1.1.</span> Level 2 caption.</p>
1355 </figcaption>
1356 </figure>
1357 <figcaption>
1358 <p><span class="caption-prefix">Figure 1.</span> Level 1 caption.</p>
1359 </figcaption>
1360 </figure>
1361 ''',
1362 True
1363 )
1364
1365 def test_depth(self):
1366 """Test level depth."""
1367
1368 self.check_markdown(
1369 R"""
1370 Paragraph
1371 /// figure-caption
1372 Caption 1
1373 ///
1374
1375 Paragraph
1376 /// figure-caption
1377 Caption 1.1.1
1378 ///
1379
1380 /// figure-caption | ^1
1381 Caption 1.1
1382 ///
1383
1384 Paragraph
1385 /// figure-caption | ^1
1386 Caption 2.1
1387 ///
1388
1389 /// figure-caption
1390 Caption 2
1391 ///
1392 """,
1393 """
1394 <figure id="__figure-caption_1">
1395 <p>Paragraph</p>
1396 <figcaption>
1397 <p><span class="caption-prefix">Figure 1.</span> Caption 1</p>
1398 </figcaption>
1399 </figure>
1400 <figure id="__figure-caption_1_1">
1401 <figure id="__figure-caption_1_1_1">
1402 <p>Paragraph</p>
1403 <figcaption>
1404 <p><span class="caption-prefix">Figure 1.1.1.</span> Caption 1.1.1</p>
1405 </figcaption>
1406 </figure>
1407 <figcaption>
1408 <p><span class="caption-prefix">Figure 1.1.</span> Caption 1.1</p>
1409 </figcaption>
1410 </figure>
1411 <figure id="__figure-caption_2">
1412 <figure id="__figure-caption_2_1_1">
1413 <p>Paragraph</p>
1414 <figcaption>
1415 <p><span class="caption-prefix">Figure 2.1.1.</span> Caption 2.1</p>
1416 </figcaption>
1417 </figure>
1418 <figcaption>
1419 <p><span class="caption-prefix">Figure 2.</span> Caption 2</p>
1420 </figcaption>
1421 </figure>
1422 """,
1423 True
1424 )
1425
1426 def test_manual_number(self):
1427 """Test manual number."""
1428
1429 self.check_markdown(
1430 R"""
1431 Paragraph
1432 /// figure-caption
1433 Caption 4.2.1
1434 ///
1435
1436 /// figure-caption | 4.2
1437 Caption 4.2
1438 ///
1439
1440
1441 Paragraph
1442 /// figure-caption
1443 Caption 5.2.1
1444 ///
1445
1446 /// figure-caption | 5.2
1447 Caption 5.2
1448 ///
1449
1450 /// figure-caption
1451 Caption 5
1452 ///
1453 """,
1454 """
1455 <figure id="__figure-caption_4_2">
1456 <figure id="__figure-caption_4_2_1">
1457 <p>Paragraph</p>
1458 <figcaption>
1459 <p><span class="caption-prefix">Figure 4.2.1.</span> Caption 4.2.1</p>
1460 </figcaption>
1461 </figure>
1462 <figcaption>
1463 <p><span class="caption-prefix">Figure 4.2.</span> Caption 4.2</p>
1464 </figcaption>
1465 </figure>
1466 <figure id="__figure-caption_5">
1467 <figure id="__figure-caption_5_2">
1468 <figure id="__figure-caption_5_2_1">
1469 <p>Paragraph</p>
1470 <figcaption>
1471 <p><span class="caption-prefix">Figure 5.2.1.</span> Caption 5.2.1</p>
1472 </figcaption>
1473 </figure>
1474 <figcaption>
1475 <p><span class="caption-prefix">Figure 5.2.</span> Caption 5.2</p>
1476 </figcaption>
1477 </figure>
1478 <figcaption>
1479 <p><span class="caption-prefix">Figure 5.</span> Caption 5</p>
1480 </figcaption>
1481 </figure>
1482 """,
1483 True
1484 )
1485
1486
1487 def test_manual_number_increment_levels(self):
1488 """Test that forced levels and manual numbers with auto works."""
1489
1490 self.check_markdown(
1491 R"""
1492 Paragraph
1493 /// figure-caption | 1.1
1494 Caption 1.1
1495 ///
1496
1497 Paragraph
1498 /// figure-caption | ^1
1499 Caption 1.2
1500 ///
1501
1502 Paragraph
1503 /// figure-caption | 2.1
1504 Caption 2.1
1505 ///
1506
1507 Paragraph
1508 /// figure-caption | ^1
1509 Caption 2.2
1510 ///
1511 """,
1512 """
1513 <figure id="__figure-caption_1_1">
1514 <p>Paragraph</p>
1515 <figcaption>
1516 <p><span class="caption-prefix">Figure 1.1.</span> Caption 1.1</p>
1517 </figcaption>
1518 </figure>
1519 <figure id="__figure-caption_1_2">
1520 <p>Paragraph</p>
1521 <figcaption>
1522 <p><span class="caption-prefix">Figure 1.2.</span> Caption 1.2</p>
1523 </figcaption>
1524 </figure>
1525 <figure id="__figure-caption_2_1">
1526 <p>Paragraph</p>
1527 <figcaption>
1528 <p><span class="caption-prefix">Figure 2.1.</span> Caption 2.1</p>
1529 </figcaption>
1530 </figure>
1531 <figure id="__figure-caption_2_2">
1532 <p>Paragraph</p>
1533 <figcaption>
1534 <p><span class="caption-prefix">Figure 2.2.</span> Caption 2.2</p>
1535 </figcaption>
1536 </figure>
1537 """,
1538 True
1539 )
1540
1541
1542 class TestBlocksCaptionAutoLevel(util.MdCase):
1543 """Test Blocks caption cases with `auto` level."""
1544
1545 extension = ['pymdownx.blocks.caption']
1546 extension_configs = {
1547 'pymdownx.blocks.caption': {
1548 'auto_level': 2
1549 }
1550 }
1551
1552 def test_caption(self):
1553 """Test basic caption with `auto` level."""
1554
1555 self.check_markdown(
1556 R'''
1557 A paragraph with a caption.
1558 /// figure-caption
1559 This is the caption.
1560 ///
1561 ''',
1562 R'''
1563 <figure id="__figure-caption_1">
1564 <p>A paragraph with a caption.</p>
1565 <figcaption>
1566 <p><span class="caption-prefix">Figure 1.</span> This is the caption.</p>
1567 </figcaption>
1568 </figure>
1569 ''',
1570 True
1571 )
1572
1573 def test_nested_captions(self):
1574 """Test nested captions with `auto` level."""
1575
1576 self.check_markdown(
1577 R'''
1578 A paragraph with a caption.
1579 /// figure-caption
1580 Level 3 caption.
1581 ///
1582 /// figure-caption
1583 Level 2 caption.
1584 ///
1585 /// figure-caption
1586 Level 1 caption.
1587 ///
1588 ''',
1589 R'''
1590 <figure id="__figure-caption_1">
1591 <figure id="__figure-caption_1_1">
1592 <figure>
1593 <p>A paragraph with a caption.</p>
1594 <figcaption>
1595 <p>Level 3 caption.</p>
1596 </figcaption>
1597 </figure>
1598 <figcaption>
1599 <p><span class="caption-prefix">Figure 1.1.</span> Level 2 caption.</p>
1600 </figcaption>
1601 </figure>
1602 <figcaption>
1603 <p><span class="caption-prefix">Figure 1.</span> Level 1 caption.</p>
1604 </figcaption>
1605 </figure>
1606 ''',
1607 True
1608 )
1609
1610 def test_nested_consecutive_captions(self):
1611 """Test nested consecutive captions with `auto` level."""
1612
1613 self.check_markdown(
1614 R'''
1615 A paragraph with a caption.
1616 /// figure-caption
1617 Level 3 caption.
1618 ///
1619 /// figure-caption
1620 Level 2 caption.
1621 ///
1622 /// figure-caption
1623 Level 1 caption.
1624 ///
1625
1626 A paragraph with a caption.
1627 /// figure-caption
1628 Level 2 caption.
1629 ///
1630 /// figure-caption
1631 Level 1 caption.
1632 ///
1633 ''',
1634 R'''
1635 <figure id="__figure-caption_1">
1636 <figure id="__figure-caption_1_1">
1637 <figure>
1638 <p>A paragraph with a caption.</p>
1639 <figcaption>
1640 <p>Level 3 caption.</p>
1641 </figcaption>
1642 </figure>
1643 <figcaption>
1644 <p><span class="caption-prefix">Figure 1.1.</span> Level 2 caption.</p>
1645 </figcaption>
1646 </figure>
1647 <figcaption>
1648 <p><span class="caption-prefix">Figure 1.</span> Level 1 caption.</p>
1649 </figcaption>
1650 </figure>
1651 <figure id="__figure-caption_2">
1652 <figure id="__figure-caption_2_1">
1653 <p>A paragraph with a caption.</p>
1654 <figcaption>
1655 <p><span class="caption-prefix">Figure 2.1.</span> Level 2 caption.</p>
1656 </figcaption>
1657 </figure>
1658 <figcaption>
1659 <p><span class="caption-prefix">Figure 2.</span> Level 1 caption.</p>
1660 </figcaption>
1661 </figure>
1662 ''',
1663 True
1664 )
1665
1666 def test_depth(self):
1667 """Test depth with auto level limit."""
1668
1669 self.check_markdown(
1670 R"""
1671 Paragraph
1672 /// figure-caption
1673 Caption 1
1674 ///
1675
1676 Paragraph
1677 /// figure-caption | ^1
1678 Caption 1.1
1679 ///
1680
1681 Paragraph
1682 /// figure-caption | ^2
1683 Caption None
1684 ///
1685 """,
1686 """
1687 <figure id="__figure-caption_1">
1688 <p>Paragraph</p>
1689 <figcaption>
1690 <p><span class="caption-prefix">Figure 1.</span> Caption 1</p>
1691 </figcaption>
1692 </figure>
1693 <figure id="__figure-caption_1_1">
1694 <p>Paragraph</p>
1695 <figcaption>
1696 <p><span class="caption-prefix">Figure 1.1.</span> Caption 1.1</p>
1697 </figcaption>
1698 </figure>
1699 <figure>
1700 <p>Paragraph</p>
1701 <figcaption>
1702 <p>Caption None</p>
1703 </figcaption>
1704 </figure>
1705 """,
1706 True
1707 )
1708
1709 def test_manual_numbers(self):
1710 """Test manual numbers with auto level limit."""
1711
1712 self.check_markdown(
1713 R"""
1714 Paragraph
1715 /// figure-caption | 1
1716 Caption 1
1717 ///
1718
1719 Paragraph
1720 /// figure-caption | 2.3
1721 Caption 2.3
1722 ///
1723
1724 Paragraph
1725 /// figure-caption | 4.3.1
1726 Caption None
1727 ///
1728 """,
1729 """
1730 <figure id="__figure-caption_1">
1731 <p>Paragraph</p>
1732 <figcaption>
1733 <p><span class="caption-prefix">Figure 1.</span> Caption 1</p>
1734 </figcaption>
1735 </figure>
1736 <figure id="__figure-caption_2_3">
1737 <p>Paragraph</p>
1738 <figcaption>
1739 <p><span class="caption-prefix">Figure 2.3.</span> Caption 2.3</p>
1740 </figcaption>
1741 </figure>
1742 <figure id="__figure-caption_4_3_1">
1743 <p>Paragraph</p>
1744 <figcaption>
1745 <p><span class="caption-prefix">Figure 4.3.1.</span> Caption None</p>
1746 </figcaption>
1747 </figure>
1748 """,
1749 True
1750 )
1751
1752
1753 class TestBlocksCaptionAutoLevelPrepend(util.MdCase):
1754 """Test Blocks caption cases with `auto` level."""
1755
1756 extension = ['pymdownx.blocks.caption']
1757 extension_configs = {
1758 'pymdownx.blocks.caption': {
1759 'auto_level': 2,
1760 'prepend': True
1761 }
1762 }
1763
1764 def test_caption(self):
1765 """Test basic caption with `auto` level and `prepend`."""
1766
1767 self.check_markdown(
1768 R'''
1769 A paragraph with a caption.
1770 /// figure-caption
1771 This is the caption.
1772 ///
1773 ''',
1774 R'''
1775 <figure id="__figure-caption_1">
1776 <figcaption>
1777 <p><span class="caption-prefix">Figure 1.</span> This is the caption.</p>
1778 </figcaption>
1779 <p>A paragraph with a caption.</p>
1780 </figure>
1781 ''',
1782 True
1783 )
1784
1785 def test_nested_captions(self):
1786 """Test nested captions with `auto` level and `prepend`."""
1787
1788 self.check_markdown(
1789 R'''
1790 A paragraph with a caption.
1791 /// figure-caption
1792 Level 3 caption.
1793 ///
1794 /// figure-caption
1795 Level 2 caption.
1796 ///
1797 /// figure-caption
1798 Level 1 caption.
1799 ///
1800 ''',
1801 R'''
1802 <figure id="__figure-caption_1">
1803 <figcaption>
1804 <p><span class="caption-prefix">Figure 1.</span> Level 1 caption.</p>
1805 </figcaption>
1806 <figure id="__figure-caption_1_1">
1807 <figcaption>
1808 <p><span class="caption-prefix">Figure 1.1.</span> Level 2 caption.</p>
1809 </figcaption>
1810 <figure>
1811 <figcaption>
1812 <p>Level 3 caption.</p>
1813 </figcaption>
1814 <p>A paragraph with a caption.</p>
1815 </figure>
1816 </figure>
1817 </figure>
1818 ''',
1819 True
1820 )
1821
1822 def test_nested_consecutive_captions(self):
1823 """Test nested consecutive captions with `auto` level and `prepend`."""
1824
1825 self.check_markdown(
1826 R'''
1827 A paragraph with a caption.
1828 /// figure-caption
1829 Level 3 caption.
1830 ///
1831 /// figure-caption
1832 Level 2 caption.
1833 ///
1834 /// figure-caption
1835 Level 1 caption.
1836 ///
1837
1838 A paragraph with a caption.
1839 /// figure-caption
1840 Level 2 caption.
1841 ///
1842 /// figure-caption
1843 Level 1 caption.
1844 ///
1845 ''',
1846 R'''
1847 <figure id="__figure-caption_1">
1848 <figcaption>
1849 <p><span class="caption-prefix">Figure 1.</span> Level 1 caption.</p>
1850 </figcaption>
1851 <figure id="__figure-caption_1_1">
1852 <figcaption>
1853 <p><span class="caption-prefix">Figure 1.1.</span> Level 2 caption.</p>
1854 </figcaption>
1855 <figure>
1856 <figcaption>
1857 <p>Level 3 caption.</p>
1858 </figcaption>
1859 <p>A paragraph with a caption.</p>
1860 </figure>
1861 </figure>
1862 </figure>
1863 <figure id="__figure-caption_2">
1864 <figcaption>
1865 <p><span class="caption-prefix">Figure 2.</span> Level 1 caption.</p>
1866 </figcaption>
1867 <figure id="__figure-caption_2_1">
1868 <figcaption>
1869 <p><span class="caption-prefix">Figure 2.1.</span> Level 2 caption.</p>
1870 </figcaption>
1871 <p>A paragraph with a caption.</p>
1872 </figure>
1873 </figure>
1874 ''',
1875 True
1876 )
1877
1878 def test_manual_prepend(self):
1879 """Test manual prepend."""
1880
1881 self.check_markdown(
1882 R"""
1883 Text
1884 /// figure-caption | <
1885 Prepended
1886 ///
1887
1888 Text
1889 /// figure-caption | >
1890 Appended
1891 ///
1892 """,
1893 R"""
1894 <figure id="__figure-caption_1">
1895 <figcaption>
1896 <p><span class="caption-prefix">Figure 1.</span> Prepended</p>
1897 </figcaption>
1898 <p>Text</p>
1899 </figure>
1900 <figure id="__figure-caption_2">
1901 <p>Text</p>
1902 <figcaption>
1903 <p><span class="caption-prefix">Figure 2.</span> Appended</p>
1904 </figcaption>
1905 </figure>
1906 """,
1907 True
1908 )
1909
1910
1911 class TestBlocksCaptionCustomPrefix(util.MdCase):
1912 """Test Blocks caption cases with `auto` level."""
1913
1914 extension = ['pymdownx.blocks.caption']
1915 extension_configs = {
1916 'pymdownx.blocks.caption': {
1917 'types': [
1918 'caption',
1919 {
1920 'name': 'figure-caption',
1921 'prefix': 'Figure <span class="caption-num">{}</span>.'
1922 },
1923 {
1924 'name': 'table-caption',
1925 'prefix': 'Table <span class="caption-num">{}</span>.'
1926 }
1927 ]
1928 }
1929 }
1930
1931 def test_custom_prefix(self):
1932 """Test custom prefix."""
1933
1934 self.check_markdown(
1935 R'''
1936 A paragraph with a caption.
1937 /// figure-caption
1938 This is the caption.
1939 ///
1940 ''',
1941 R'''
1942 <figure id="__figure-caption_1">
1943 <p>A paragraph with a caption.</p>
1944 <figcaption>
1945 <p><span class="caption-prefix">Figure <span class="caption-num">1</span>.</span> This is the caption.</p>
1946 </figcaption>
1947 </figure>
1948 ''',
1949 True
1950 )