| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | /** |
| 4 | 4 | * Plugin Name: SimpleTOC - Table of Contents Block |
| 5 | 5 | * Plugin URI: https://marc.tv/simpletoc-wordpress-inhaltsverzeichnis-plugin-gutenberg/ |
| 6 | 6 | * Description: SEO-friendly Table of Contents Gutenberg block. No JavaScript and no CSS means faster loading. |
| 7 | - * Version: 5.0.32 | |
| 7 | + * Version: 5.0.29 | |
| 8 | 8 | * Author: Marc Tönsing |
| 9 | 9 | * Author URI: https://marc.tv |
| 10 | 10 | * Text Domain: simpletoc |
| 11 | 11 | * License: GPL v2 or later |
| @@ -85,9 +85,9 @@ | ||
| 85 | 85 | }, 10, 4 ); |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * Sets the default value of translatable attributes. |
| 89 | - * | |
| 89 | + * | |
| 90 | 90 | * Values inside block.json are static strings that are not translated. This |
| 91 | 91 | * filter inserts relevant translations i |
| 92 | 92 | * |
| 93 | 93 | * @param array $settings Array of determined settings for registering a block type. |
| @@ -173,15 +173,10 @@ | ||
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | $pre_html = ''; |
| 176 | 176 | $post_html = ''; |
| 177 | - | |
| 178 | - // By default, the wrapper is not enabled because it causes problems on some themes | |
| 179 | - $wrapper_enabled = apply_filters( 'simpletoc_wrapper_enabled', false ); | |
| 180 | - | |
| 181 | - if ( $className !== ''|| $wrapper_enabled ) { | |
| 182 | - $wrapper_attrs = get_block_wrapper_attributes( [ 'class' => 'simpletoc' ] ); | |
| 183 | - $pre_html = "<div $wrapper_attrs>"; | |
| 177 | + if ( $className != '' ) { | |
| 178 | + $pre_html = '<div class="simpletoc ' . $className . '">'; | |
| 184 | 179 | $post_html = '</div>'; |
| 185 | 180 | } |
| 186 | 181 | |
| 187 | 182 | $post = get_post(); |
| @@ -269,52 +264,46 @@ | ||
| 269 | 264 | |
| 270 | 265 | /** |
| 271 | 266 | * Return all headings with a recursive walk through all blocks. |
| 272 | 267 | * This includes groups and reusable block with groups within reusable blocks. |
| 273 | - * @var array[] $blocks | |
| 274 | - * @return array[] | |
| 275 | 268 | */ |
| 276 | -function filter_headings_recursive( array $blocks ): array { | |
| 277 | - $arr = []; | |
| 278 | - // allow developers to ignore specific blocks | |
| 279 | - $ignored_blocks = apply_filters( 'simpletoc_excluded_blocks', [] ); | |
| 280 | 269 | |
| 281 | - foreach ( $blocks as $innerBlock ) { | |
| 270 | +function filter_headings_recursive( $blocks ) | |
| 271 | +{ | |
| 272 | + $arr = array(); | |
| 282 | 273 | |
| 283 | - if ( is_array( $innerBlock ) ) { | |
| 274 | + foreach ($blocks as $block => $innerBlock) { | |
| 284 | 275 | |
| 285 | - // if block is ignored, skip | |
| 286 | - if ( isset( $innerBlock['blockName'] ) && in_array( $innerBlock['blockName'], $ignored_blocks ) ) { | |
| 287 | - continue; | |
| 288 | - } | |
| 276 | + if (is_array($innerBlock)) { | |
| 289 | 277 | |
| 290 | - if ( isset( $innerBlock['attrs']['ref'] ) ) { | |
| 291 | - // search in reusable blocks | |
| 292 | - $e_arr = parse_blocks( get_post( $innerBlock['attrs']['ref'] )->post_content ); | |
| 293 | - $arr = array_merge( filter_headings_recursive( $e_arr ), $arr ); | |
| 294 | - } else { | |
| 295 | - // search in groups | |
| 296 | - $arr = array_merge( filter_headings_recursive( $innerBlock ), $arr ); | |
| 297 | - } | |
| 298 | - } else { | |
| 278 | + if (isset($innerBlock['attrs']['ref'])) { | |
| 279 | + // search in reusable blocks | |
| 280 | + $e_arr = parse_blocks(get_post($innerBlock['attrs']['ref'])->post_content); | |
| 281 | + $arr = array_merge(filter_headings_recursive($e_arr), $arr); | |
| 282 | + } else { | |
| 283 | + // search in groups | |
| 284 | + $arr = array_merge(filter_headings_recursive($innerBlock), $arr); | |
| 285 | + } | |
| 286 | + } else { | |
| 299 | 287 | |
| 300 | - if ( isset( $blocks['blockName'] ) && ( $blocks['blockName'] === 'core/heading' ) && $innerBlock !== 'core/heading' ) { | |
| 301 | - // make sure it's a headline. | |
| 302 | - if ( preg_match( "/(<h1|<h2|<h3|<h4|<h5|<h6)/i", $innerBlock ) ) { | |
| 303 | - $arr[] = $innerBlock; | |
| 304 | - } | |
| 305 | - } | |
| 288 | + if (isset($blocks['blockName']) && ( $blocks['blockName'] === 'core/heading' ) && $innerBlock !== 'core/heading') { | |
| 289 | + // make sure its a headline. | |
| 290 | + if (preg_match("/(<h1|<h2|<h3|<h4|<h5|<h6)/i", $innerBlock)) { | |
| 291 | + $arr[] = $innerBlock; | |
| 292 | + } | |
| 293 | + } | |
| 306 | 294 | |
| 307 | - if ( isset( $blocks['blockName'] ) && ( $blocks['blockName'] === 'generateblocks/headline' ) && $innerBlock !== 'core/heading' ) { | |
| 308 | - // make sure it's a headline. | |
| 309 | - if ( preg_match( "/(<h1|<h2|<h3|<h4|<h5|<h6)/i", $innerBlock ) ) { | |
| 310 | - $arr[] = $innerBlock; | |
| 311 | - } | |
| 312 | - } | |
| 313 | - } | |
| 314 | - } | |
| 295 | + if (isset($blocks['blockName']) && ( $blocks['blockName'] === 'generateblocks/headline' ) && $innerBlock !== 'core/heading') { | |
| 296 | + // make sure its a headline. | |
| 297 | + if (preg_match("/(<h1|<h2|<h3|<h4|<h5|<h6)/i", $innerBlock)) { | |
| 298 | + $arr[] = $innerBlock; | |
| 299 | + } | |
| 300 | + } | |
| 301 | + } | |
| 302 | + } | |
| 315 | 303 | |
| 316 | - return $arr; | |
| 304 | + return $arr; | |
| 305 | + | |
| 317 | 306 | } |
| 318 | 307 | |
| 319 | 308 | /** |
| 320 | 309 | * Remove all problematic characters for toc links |