Skip to content

Commit 813e0b0

Browse files
authored
Table of Contents Add IDs to all heading levels (#695)
1 parent be7e1ee commit 813e0b0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

mu-plugins/blocks/table-of-contents/index.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ function render( $attributes, $content, $block ) {
7171
$last_item = false;
7272

7373
foreach ( $items as $item ) {
74+
if ( $item['level'] > 3 ) {
75+
continue;
76+
}
77+
7478
if ( $last_item ) {
7579
if ( $last_item < $item['level'] ) {
7680
$content .= "\n<ul>\n";
@@ -113,7 +117,7 @@ function( $content ) use ( $items ) {
113117
* @return array A list of heading objects.
114118
*/
115119
function get_headings( $content ) {
116-
$tag = 'h(?P<level>[1-3])';
120+
$tag = 'h(?P<level>[1-6])';
117121
preg_match_all( "/(?P<tag><{$tag}(?P<attrs>[^>]*)>)(?P<title>.*?)(<\/{$tag}>)/iJ", $content, $matches, PREG_SET_ORDER );
118122

119123
foreach ( $matches as $i => $item ) {

0 commit comments

Comments
 (0)