diff --git a/includes/utilities.php b/includes/utilities.php
index db3770d..1bf8d69 100644
--- a/includes/utilities.php
+++ b/includes/utilities.php
@@ -86,7 +86,22 @@ function build_sommaire_from_content($postID)
$titleBlocks = array_filter(
$blocks,
function ($block) {
- return $block['blockName'] === 'core/heading' && isset($block['attrs']['level']) && in_array($block['attrs']['level'], array(2, 3), true);
+ // Vérifier si c'est un bloc heading
+ if ($block['blockName'] !== 'core/heading') {
+ return false;
+ }
+
+ // Extraire le niveau depuis le HTML si les attributs sont vides
+ if (empty($block['attrs']['level'])) {
+ // Chercher seulement h2 dans le HTML
+ if (preg_match('/
]*>/i', $block['innerHTML'], $matches)) {
+ return true;
+ }
+ return false;
+ }
+
+ // Utiliser le niveau des attributs s'il existe
+ return $block['attrs']['level'] === 2;
}
);
@@ -94,17 +109,24 @@ function build_sommaire_from_content($postID)
foreach ($titleBlocks as $block) {
$title = strip_tags($block['innerHTML']);
+
+ // Extraire le niveau depuis le HTML ou les attributs
+ $level = $block['attrs']['level'] ?? null;
+ if (!$level && preg_match('/]*>/i', $block['innerHTML'], $matches)) {
+ $level = 2;
+ }
+
+ if ($level !== 2) continue;
+
$anchor = $block['attrs']['idName'] ?? sanitize_title($title);
- $level = $block['attrs']['level'];
$outputIndex[] = [
'title' => $title,
'anchor' => $anchor,
+ 'level' => $level,
];
}
-
-
return $outputIndex;
}