FIX Handling when h2 anchors start with date or number
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
54b671d902
commit
961fa2e4c5
|
|
@ -80,6 +80,11 @@ function dynamiques_render_article_inject_ids_to_headings($content)
|
||||||
$slug = 'anchor';
|
$slug = 'anchor';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ajouter un préfixe si l'ancre commence par un chiffre
|
||||||
|
if (preg_match('/^[0-9]/', $slug)) {
|
||||||
|
$slug = 'anchor-' . $slug;
|
||||||
|
}
|
||||||
|
|
||||||
return $slug;
|
return $slug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,12 @@ function build_sommaire_from_content($postID)
|
||||||
|
|
||||||
$anchor = $block['attrs']['idName'] ?? sanitize_title($title);
|
$anchor = $block['attrs']['idName'] ?? sanitize_title($title);
|
||||||
|
|
||||||
|
// Ajouter un préfixe si l'ancre commence par un chiffre
|
||||||
|
if (!empty($anchor) && preg_match('/^[0-9]/', $anchor)) {
|
||||||
|
$anchor = 'anchor-' . $anchor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$outputIndex[] = [
|
$outputIndex[] = [
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'anchor' => $anchor,
|
'anchor' => $anchor,
|
||||||
|
|
@ -183,3 +189,31 @@ function apply_footnotes_urls_to_content($content)
|
||||||
|
|
||||||
return $dom->saveHTML();
|
return $dom->saveHTML();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Endpoint AJAX pour sanitize_title
|
||||||
|
add_action('wp_ajax_sanitize_title_ajax', 'sanitize_title_ajax_handler');
|
||||||
|
add_action('wp_ajax_nopriv_sanitize_title_ajax', 'sanitize_title_ajax_handler');
|
||||||
|
|
||||||
|
function sanitize_title_ajax_handler()
|
||||||
|
{
|
||||||
|
// Vérifier le nonce pour la sécurité
|
||||||
|
if (!wp_verify_nonce($_POST['nonce'], 'sanitize_title_nonce')) {
|
||||||
|
wp_die('Erreur de sécurité');
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = sanitize_text_field($_POST['title']);
|
||||||
|
$sanitized_title = sanitize_title($title);
|
||||||
|
|
||||||
|
wp_send_json_success(array('sanitized_title' => $sanitized_title));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajouter le script et les variables localisées
|
||||||
|
add_action('wp_enqueue_scripts', 'add_sanitize_title_script');
|
||||||
|
|
||||||
|
function add_sanitize_title_script()
|
||||||
|
{
|
||||||
|
wp_localize_script('jquery', 'sanitize_title_ajax', array(
|
||||||
|
'ajax_url' => admin_url('admin-ajax.php'),
|
||||||
|
'nonce' => wp_create_nonce('sanitize_title_nonce')
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user