diff options
Diffstat (limited to 'inc/html.php')
-rw-r--r-- | inc/html.php | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/inc/html.php b/inc/html.php index 7f5a46b93..1a2d7daef 100644 --- a/inc/html.php +++ b/inc/html.php @@ -899,45 +899,41 @@ function html_li_default($item){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function html_buildlist($data,$class,$func,$lifunc='html_li_default'){ +function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){ if (count($data) === 0) { return ''; } $start_level = $data[0]['level']; - $ret = ''; - - if ($start_level < 2) { - // Trigger building a wrapper ul if the first level is - // 0 (we have a root object) or 1 (just the root content) - --$start_level; - } - $level = $start_level; + $ret = ''; + $open = 0; foreach ($data as $item){ if( $item['level'] > $level ){ //open new list for($i=0; $i<($item['level'] - $level); $i++){ - if ($i) $ret .= "<li class=\"clear\">\n"; + if ($i) $ret .= "<li class=\"clear\">"; $ret .= "\n<ul class=\"$class\">\n"; + $open++; } + $level = $item['level']; + }elseif( $item['level'] < $level ){ //close last item $ret .= "</li>\n"; - for ($i=0; $i<($level - $item['level']); $i++){ + while( $level > $item['level'] && $open > 0 ){ //close higher lists $ret .= "</ul>\n</li>\n"; + $level--; + $open--; } } elseif ($ret !== '') { - //close last item + //close previous item $ret .= "</li>\n"; } - //remember current level - $level = $item['level']; - //print item $ret .= call_user_func($lifunc,$item); $ret .= '<div class="li">'; @@ -947,8 +943,15 @@ function html_buildlist($data,$class,$func,$lifunc='html_li_default'){ } //close remaining items and lists - while(--$level >= $start_level) { - $ret .= "</li></ul>\n"; + $ret .= "</li>\n"; + while($open-- > 0) { + $ret .= "</ul></li>\n"; + } + + if ($forcewrapper || $start_level < 2) { + // Trigger building a wrapper ul if the first level is + // 0 (we have a root object) or 1 (just the root content) + $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n"; } return $ret; @@ -1694,7 +1697,7 @@ function html_TOC($toc){ $out .= $lang['toc']; $out .= '</div>'.DOKU_LF; $out .= '<div id="toc__inside">'.DOKU_LF; - $out .= html_buildlist($toc,'toc','html_list_toc'); + $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true); $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; $out .= '<!-- TOC END -->'.DOKU_LF; return $out; |