@@ -368,7 +368,7 @@ public function replaceListIsolatedDiffTags()
368368 */
369369 protected function getListsContent (array $ contentArray , $ stripTags = true )
370370 {
371- $ lematches = array (' content ' => '' , ' kids ' => array () );
371+ $ lematches = array ();
372372 $ arrayDepth = 0 ;
373373 $ status = "//////////////////// STATUS \\\\\\\\\\\\\\\\\\\\\\" ;
374374 $ nestedCount = array ();
@@ -394,7 +394,7 @@ protected function getListsContent(array $contentArray, $stripTags = true)
394394 if ($ arrayDepth > 0 ) {
395395 //$this->dump(array('arrayDepth' => $arrayDepth, 'prev' => $previousDepth, 'action' => '==', 'word' => $word, 'changed' => $changed), $status);
396396 $ this ->addStringToArrayByDepth ($ word , $ lematches , $ arrayDepth , 1 , $ nestedCount );
397- // $this->dump($lematches, '---------- total array at end of this loop ---------');
397+ $ this ->dump ($ lematches , '---------- total array at end of this loop --------- ' );
398398 }
399399 }
400400
@@ -409,15 +409,23 @@ protected function getListsContent(array $contentArray, $stripTags = true)
409409
410410 protected function addStringToArrayByDepth ($ word , &$ array , $ targetDepth , $ thisDepth , $ nestedCount )
411411 {
412- // $this->dump(func_get_args(), '============ addstringfunction vars');
412+ $ this ->dump (func_get_args (), '============ addstringfunction vars ' );
413413 //$this->dump($array);
414414
415415 // determine what depth we're at
416416 if ($ targetDepth == $ thisDepth ) {
417417 // decide on what to do at this level
418418
419- // if we're on depth 1, add content
420- $ array ['content ' ] .= $ word ;
419+ if (array_key_exists ('content ' , $ array )) {
420+ $ array ['content ' ] .= $ word ;
421+ } else {
422+ // if we're on depth 1, add content
423+ if ($ nestedCount [$ targetDepth ] > count ($ array )) {
424+ $ array [] = array ('content ' => '' , 'kids ' => array ());
425+ }
426+
427+ $ array [count ($ array ) - 1 ]['content ' ] .= $ word ;
428+ }
421429
422430 //$this->dump($array, '========= ADDED CONTENT TO THIS ARRAY ==========');
423431 } else {
@@ -428,20 +436,47 @@ protected function addStringToArrayByDepth($word, &$array, $targetDepth, $thisDe
428436 $newArray = array('content' => '', 'kids' => array());
429437 $array['kids'][] = $newArray;
430438 }*/
439+ $ newArray = array ('content ' => '' , 'kids ' => array ());
431440
432- //$this->dump(($depth > $previousDepth), "!!! depth greater than prev");
433- //$this->dump(($previousDepth > $depth), "!!! depth less than prev");
434- if ($ nestedCount [$ targetDepth ] > count ($ array ['kids ' ])) {
435- $ newArray = array ('content ' => '' , 'kids ' => array ());
436- $ array ['kids ' ][] = $ newArray ;
437- $ array ['content ' ] .= "[[REPLACE_LIST_ITEM]] " ;
441+ if (array_key_exists ('kids ' , $ array )) {
442+ if ($ nestedCount [$ targetDepth ] > count ($ array ['kids ' ])) {
443+ $ array ['kids ' ][] = $ newArray ;
444+ $ array ['content ' ] .= "[[REPLACE_LIST_ITEM]] " ;
445+ }
446+
447+ // continue to the next depth
448+ $ thisDepth ++;
449+
450+ // get last kid and send to next depth
451+
452+ $ this ->addStringToArrayByDepth (
453+ $ word ,
454+ $ array ['kids ' ][count ($ array ['kids ' ]) - 1 ],
455+ $ targetDepth ,
456+ $ thisDepth ,
457+ $ nestedCount
458+ );
459+
460+ } else {
461+ $ this ->dump ($ array , "================PREP " );
462+ if ($ nestedCount [$ targetDepth ] > count ($ array [count ($ array ) - 1 ]['kids ' ])) {
463+ $ array [count ($ array ) - 1 ]['kids ' ][] = $ newArray ;
464+ $ array [count ($ array ) - 1 ]['content ' ] .= "[[REPLACE_LIST_ITEM]] " ;
465+ }
466+ $ this ->dump ($ array , "================POSTPREP " );
467+ // continue to the next depth
468+ $ thisDepth ++;
469+
470+ // get last kid and send to next depth
471+
472+ $ this ->addStringToArrayByDepth (
473+ $ word ,
474+ $ array [count ($ array ) - 1 ]['kids ' ][count ($ array [count ($ array ) - 1 ]['kids ' ]) - 1 ],
475+ $ targetDepth ,
476+ $ thisDepth ,
477+ $ nestedCount
478+ );
438479 }
439- // continue to the next depth
440- $ thisDepth ++;
441-
442- // get last kid and send to next depth
443-
444- $ this ->addStringToArrayByDepth ($ word , $ array ['kids ' ][count ($ array ['kids ' ]) - 1 ], $ targetDepth , $ thisDepth , $ nestedCount );
445480 }
446481 /* Structure
447482 * $matches = array(
0 commit comments