@@ -181,8 +181,15 @@ fn traverse_children(root: &mut hast::Root) {
181
181
let mut container_content_end_index = 0 ;
182
182
let mut index = 0 ;
183
183
while index < root. children . len ( ) {
184
- let child = & root. children [ index] ;
184
+ let child = & mut root. children [ index] ;
185
185
if let hast:: Node :: Element ( element) = child {
186
+ let mut element_as_root = hast:: Root {
187
+ children : element. children . clone ( ) ,
188
+ position : element. position . clone ( ) ,
189
+ } ;
190
+ traverse_children ( & mut element_as_root) ;
191
+ element. children = element_as_root. children ;
192
+
186
193
// Meet the start of the container
187
194
if !container_content_start {
188
195
// e.g. :::tip
@@ -986,4 +993,180 @@ mod tests {
986
993
} )
987
994
) ;
988
995
}
996
+
997
+ #[ test]
998
+ fn test_container_plugin_with_nested_in_list ( ) {
999
+ let mut root = hast:: Node :: Root ( hast:: Root {
1000
+ children : vec ! [
1001
+ hast:: Node :: Element ( hast:: Element {
1002
+ tag_name: "ol" . into( ) ,
1003
+ properties: vec![ ] ,
1004
+ children: vec![
1005
+ hast:: Node :: Element ( hast:: Element {
1006
+ tag_name: "p" . into( ) ,
1007
+ properties: vec![ ] ,
1008
+ children: vec![ hast:: Node :: Text ( hast:: Text {
1009
+ value: ":::tip Note" . into( ) ,
1010
+ position: None ,
1011
+ } ) ] ,
1012
+ position: None ,
1013
+ } ) ,
1014
+ hast:: Node :: Element ( hast:: Element {
1015
+ tag_name: "p" . into( ) ,
1016
+ properties: vec![ ] ,
1017
+ children: vec![ hast:: Node :: Text ( hast:: Text {
1018
+ value: "This is a tip" . into( ) ,
1019
+ position: None ,
1020
+ } ) ] ,
1021
+ position: None ,
1022
+ } ) ,
1023
+ hast:: Node :: Element ( hast:: Element {
1024
+ tag_name: "p" . into( ) ,
1025
+ properties: vec![ ] ,
1026
+ children: vec![ hast:: Node :: Text ( hast:: Text {
1027
+ value: ":::" . into( ) ,
1028
+ position: None ,
1029
+ } ) ] ,
1030
+ position: None ,
1031
+ } ) ,
1032
+ ] ,
1033
+ position: None ,
1034
+ } ) ,
1035
+ hast:: Node :: Element ( hast:: Element {
1036
+ tag_name: "ul" . into( ) ,
1037
+ properties: vec![ ] ,
1038
+ children: vec![
1039
+ hast:: Node :: Element ( hast:: Element {
1040
+ tag_name: "p" . into( ) ,
1041
+ properties: vec![ ] ,
1042
+ children: vec![ hast:: Node :: Text ( hast:: Text {
1043
+ value: ":::tip Note" . into( ) ,
1044
+ position: None ,
1045
+ } ) ] ,
1046
+ position: None ,
1047
+ } ) ,
1048
+ hast:: Node :: Element ( hast:: Element {
1049
+ tag_name: "p" . into( ) ,
1050
+ properties: vec![ ] ,
1051
+ children: vec![ hast:: Node :: Text ( hast:: Text {
1052
+ value: "This is a tip" . into( ) ,
1053
+ position: None ,
1054
+ } ) ] ,
1055
+ position: None ,
1056
+ } ) ,
1057
+ hast:: Node :: Element ( hast:: Element {
1058
+ tag_name: "p" . into( ) ,
1059
+ properties: vec![ ] ,
1060
+ children: vec![ hast:: Node :: Text ( hast:: Text {
1061
+ value: ":::" . into( ) ,
1062
+ position: None ,
1063
+ } ) ] ,
1064
+ position: None ,
1065
+ } ) ,
1066
+ ] ,
1067
+ position: None ,
1068
+ } ) ,
1069
+ ] ,
1070
+ position : None ,
1071
+ } ) ;
1072
+
1073
+ mdx_plugin_container ( & mut root) ;
1074
+
1075
+ assert_eq ! (
1076
+ root,
1077
+ hast:: Node :: Root ( hast:: Root {
1078
+ children: vec![
1079
+ hast:: Node :: Element ( hast:: Element {
1080
+ tag_name: "ol" . into( ) ,
1081
+ properties: vec![ ] ,
1082
+ children: vec![ hast:: Node :: Element ( hast:: Element {
1083
+ tag_name: "div" . into( ) ,
1084
+ properties: vec![ (
1085
+ "className" . into( ) ,
1086
+ hast:: PropertyValue :: SpaceSeparated ( vec![ "rspress-directive" . into( ) , "tip" . into( ) ] )
1087
+ ) , ] ,
1088
+ children: vec![
1089
+ hast:: Node :: Element ( hast:: Element {
1090
+ tag_name: "div" . into( ) ,
1091
+ properties: vec![ (
1092
+ "className" . into( ) ,
1093
+ hast:: PropertyValue :: SpaceSeparated ( vec![ "rspress-directive-title" . into( ) ] )
1094
+ ) ] ,
1095
+ children: vec![ hast:: Node :: Text ( hast:: Text {
1096
+ value: "Note" . into( ) ,
1097
+ position: None ,
1098
+ } ) ] ,
1099
+ position: None ,
1100
+ } ) ,
1101
+ hast:: Node :: Element ( hast:: Element {
1102
+ tag_name: "div" . into( ) ,
1103
+ properties: vec![ (
1104
+ "className" . into( ) ,
1105
+ hast:: PropertyValue :: SpaceSeparated ( vec![ "rspress-directive-content" . into( ) ] )
1106
+ ) ] ,
1107
+ children: vec![ hast:: Node :: Element ( hast:: Element {
1108
+ tag_name: "p" . into( ) ,
1109
+ properties: vec![ ] ,
1110
+ children: vec![ hast:: Node :: Text ( hast:: Text {
1111
+ value: "This is a tip" . into( ) ,
1112
+ position: None ,
1113
+ } ) ] ,
1114
+ position: None ,
1115
+ } ) ] ,
1116
+ position: None ,
1117
+ } )
1118
+ ] ,
1119
+ position: None ,
1120
+ } ) ] ,
1121
+ position: None
1122
+ } ) ,
1123
+ hast:: Node :: Element ( hast:: Element {
1124
+ tag_name: "ul" . into( ) ,
1125
+ properties: vec![ ] ,
1126
+ children: vec![ hast:: Node :: Element ( hast:: Element {
1127
+ tag_name: "div" . into( ) ,
1128
+ properties: vec![ (
1129
+ "className" . into( ) ,
1130
+ hast:: PropertyValue :: SpaceSeparated ( vec![ "rspress-directive" . into( ) , "tip" . into( ) ] )
1131
+ ) , ] ,
1132
+ children: vec![
1133
+ hast:: Node :: Element ( hast:: Element {
1134
+ tag_name: "div" . into( ) ,
1135
+ properties: vec![ (
1136
+ "className" . into( ) ,
1137
+ hast:: PropertyValue :: SpaceSeparated ( vec![ "rspress-directive-title" . into( ) ] )
1138
+ ) ] ,
1139
+ children: vec![ hast:: Node :: Text ( hast:: Text {
1140
+ value: "Note" . into( ) ,
1141
+ position: None ,
1142
+ } ) ] ,
1143
+ position: None ,
1144
+ } ) ,
1145
+ hast:: Node :: Element ( hast:: Element {
1146
+ tag_name: "div" . into( ) ,
1147
+ properties: vec![ (
1148
+ "className" . into( ) ,
1149
+ hast:: PropertyValue :: SpaceSeparated ( vec![ "rspress-directive-content" . into( ) ] )
1150
+ ) ] ,
1151
+ children: vec![ hast:: Node :: Element ( hast:: Element {
1152
+ tag_name: "p" . into( ) ,
1153
+ properties: vec![ ] ,
1154
+ children: vec![ hast:: Node :: Text ( hast:: Text {
1155
+ value: "This is a tip" . into( ) ,
1156
+ position: None ,
1157
+ } ) ] ,
1158
+ position: None ,
1159
+ } ) ] ,
1160
+ position: None ,
1161
+ } )
1162
+ ] ,
1163
+ position: None ,
1164
+ } ) ] ,
1165
+ position: None
1166
+ } )
1167
+ ] ,
1168
+ position: None ,
1169
+ } )
1170
+ ) ;
1171
+ }
989
1172
}
0 commit comments