@@ -281,7 +281,11 @@ fn gen_paragraph(paragraph: &Paragraph, context: &mut Context) -> PrintItems {
281
281
}
282
282
}
283
283
284
- items. extend ( gen_nodes ( & paragraph. children , context) ) ;
284
+ items. extend ( gen_task_list_marker_children (
285
+ & paragraph. children ,
286
+ paragraph. marker . as_ref ( ) ,
287
+ context,
288
+ ) ) ;
285
289
items
286
290
}
287
291
@@ -736,42 +740,55 @@ fn gen_item(item: &Item, context: &mut Context) -> PrintItems {
736
740
}
737
741
}
738
742
743
+ items. extend ( gen_task_list_marker_children (
744
+ & item. children ,
745
+ item. marker . as_ref ( ) ,
746
+ context,
747
+ ) ) ;
748
+
749
+ if !item. sub_lists . is_empty ( ) {
750
+ items. push_signal ( Signal :: NewLine ) ;
751
+ if utils:: has_leading_blankline ( item. sub_lists . first ( ) . unwrap ( ) . range ( ) . start , context. file_text ) {
752
+ items. push_signal ( Signal :: NewLine ) ;
753
+ }
754
+ items. extend ( gen_nodes ( & item. sub_lists , context) ) ;
755
+ }
756
+
757
+ items
758
+ }
759
+
760
+ fn gen_task_list_marker_children (
761
+ children : & [ Node ] ,
762
+ marker : Option < & TaskListMarker > ,
763
+ context : & mut Context ,
764
+ ) -> PrintItems {
765
+ let mut items = PrintItems :: new ( ) ;
739
766
// indent the children to beyond the task list marker
740
- let marker_indent = if item . marker . is_some ( ) { 4 } else { 0 } ;
767
+ let marker_indent = if marker. is_some ( ) { 4 } else { 0 } ;
741
768
context. raw_indent_level += marker_indent;
742
- let indent_child_index_end = item
743
- . children
769
+ let indent_child_index_end = children
744
770
. iter ( )
745
771
. position ( |c| {
746
772
matches ! (
747
773
c,
748
774
Node :: List ( _) | Node :: CodeBlock ( _) | Node :: BlockQuote ( _) | Node :: Heading ( _) | Node :: Table ( _)
749
775
) || utils:: has_leading_blankline ( c. range ( ) . start , context. file_text )
750
776
} )
751
- . unwrap_or ( item . children . len ( ) ) ;
777
+ . unwrap_or ( children. len ( ) ) ;
752
778
items. extend ( with_indent_times (
753
- gen_nodes ( & item . children [ ..indent_child_index_end] , context) ,
779
+ gen_nodes ( & children[ ..indent_child_index_end] , context) ,
754
780
marker_indent,
755
781
) ) ;
756
782
context. raw_indent_level -= marker_indent;
757
783
758
784
// insert the remaining children without indent
759
- if indent_child_index_end > 0 && indent_child_index_end != item. children . len ( ) {
760
- items. push_signal ( Signal :: NewLine ) ;
761
- if utils:: has_leading_blankline ( item. children [ indent_child_index_end] . range ( ) . start , context. file_text ) {
762
- items. push_signal ( Signal :: NewLine ) ;
763
- }
764
- }
765
- items. extend ( gen_nodes ( & item. children [ indent_child_index_end..] , context) ) ;
766
-
767
- if !item. sub_lists . is_empty ( ) {
785
+ if indent_child_index_end > 0 && indent_child_index_end != children. len ( ) {
768
786
items. push_signal ( Signal :: NewLine ) ;
769
- if utils:: has_leading_blankline ( item . sub_lists . first ( ) . unwrap ( ) . range ( ) . start , context. file_text ) {
787
+ if utils:: has_leading_blankline ( children [ indent_child_index_end ] . range ( ) . start , context. file_text ) {
770
788
items. push_signal ( Signal :: NewLine ) ;
771
789
}
772
- items. extend ( gen_nodes ( & item. sub_lists , context) ) ;
773
790
}
774
-
791
+ items . extend ( gen_nodes ( & children [ indent_child_index_end.. ] , context ) ) ;
775
792
items
776
793
}
777
794
0 commit comments