Skip to content

Commit

Permalink
🐛 Fix levels issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsoyes committed Apr 18, 2020
1 parent 68bad31 commit 4213194
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions inc/table-of-contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,25 @@ function get_toc() {
continue;
}

if ( $level > $level_previous ) { // the previous title is higher h2 > h3.
$levels_to_close = $level_previous - $level;

if ( $level > $level_previous ) {
// the previous title is higher h2 > h3.
$html .= "\n<ol class='toc_sublist'><li class='toc_$level'>$link";
$levels_to_close ++;
} elseif ( $level_previous > $level ) { // the previous title is lower h4 > h2.
} elseif ( $level_previous > $level ) {
// the previous title is lower h4 > h2.

// close all opened li before closing the list.
for ( $l = 0; $l < $levels_to_close; $l++ ) {
$html .= '</li></ol>';
}
$html .= "</li>\n<li class='toc_$level'>$link";
$levels_to_close = 0;
} else { // the previous title is the same h2 = h2.

$html .= "</li>\n<li class='toc_$level'>$link";
} else {
// the previous title is the same h2 = h2.
$html .= "</li>\n<li class='toc_$level'>$link";
}

$level_previous = $level;
}

Expand Down

0 comments on commit 4213194

Please sign in to comment.