Skip to content

Commit

Permalink
better handling of german umlauts
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoensing committed Jun 21, 2020
1 parent 030ffac commit 9bd4245
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: SimpleTOC - Table of Contents Block
* Plugin URI: https://github.com/mtoensing/simpletoc
* Description: Adds a basic "Table of Contents" Gutenberg block.
* Version: 2.1
* Version: 2.2
* Author: MarcDK
* Author URI: marc.tv
* Text Domain: simpletoc
Expand Down Expand Up @@ -112,14 +112,20 @@ function render_callback($attributes, $content) {
return $output;
}

function simpletoc_sanitize_string($string){
$string_without_accents = remove_accents($string);
$sanitized_string = sanitize_title_with_dashes($string_without_accents);
return $sanitized_string;
}

function filter_block($block_content, $block) {
if ($block['blockName'] !== 'core/heading') {
return $block_content;
}

//$block_content = strip_tags($block_content, ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']);
preg_match('/\\n<(h[2-4](?:.*))>(.*)<\/(h[2-4])>\\n/', $block_content, $matches);
$link = sanitize_title_with_dashes($matches[2]);
$link = simpletoc_sanitize_string($matches[2]);
$start = preg_replace('#\s(id|class)="[^"]+"#', '', $matches[1]);
return "\n<{$start} id='{$link}'>" . $matches[2] . "</{$matches[3]}>\n";
}
Expand Down Expand Up @@ -158,7 +164,7 @@ function generateToc($matches) {
}

$title = strip_tags($match);
$link = sanitize_title_with_dashes($title);
$link = simpletoc_sanitize_string( $title );
$list .= '<a href="#' . $link . '">' . $title . '</a>';

// end lists
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: MarcDK
Tags: Gutenberg, TOC, Table of Contents, Inhaltsverzeichnis, twenty-twenty
Requires at least: 5.0
Tested up to: 5.4
Stable tag: 2.1
Stable tag: 2.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down

0 comments on commit 9bd4245

Please sign in to comment.