|
|
@ -15,20 +15,21 @@ if (!defined('_ECRIRE_INC_VERSION')) {return;} |
|
|
|
* @param string ('blockquote') $echappe, ne pas appliquer le traitement au sein de certaines balises HTML. Exemple `blockquote|article|aside|nav|section` |
|
|
|
**/ |
|
|
|
function ajuster_intertitres($texte, $decalage_ou_niveau = 1, $echappe = 'blockquote') { |
|
|
|
|
|
|
|
if (intval($decalage_ou_niveau)) { |
|
|
|
$decalage = $decalage_ou_niveau; |
|
|
|
} elseif (substr($decalage_ou_niveau, 0, 1) === 'h' and $niveau = intval(substr($decalage_ou_niveau, 1, 1))) { |
|
|
|
preg_match_all('#<h([1-6])#', $texte, $matches); |
|
|
|
$base_actuel = min($matches[1]); |
|
|
|
$decalage = $niveau - $base_actuel; |
|
|
|
} else { |
|
|
|
return $texte; |
|
|
|
|
|
|
|
$decalage = intval($decalage_ou_niveau) |
|
|
|
if (!$decalage) { |
|
|
|
if (substr($decalage_ou_niveau, 0, 1) === 'h' and $niveau = intval(substr($decalage_ou_niveau, 1, 1))) { |
|
|
|
preg_match_all('#<h([1-6])\b#', $texte, $matches); |
|
|
|
$base_actuel = min($matches[1]); |
|
|
|
$decalage = $niveau - $base_actuel; |
|
|
|
} else { |
|
|
|
return $texte; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// On echape
|
|
|
|
if ($echappe) { |
|
|
|
$preg = ',<('.$echappe.')(\s[^>]*)?>(.*)</\1>,UimsS'; |
|
|
|
$preg = ',<('.$echappe.')\b([^>]*)?>(.*)</\1>,UimsS'; |
|
|
|
$texte = echappe_html($texte, '', true, $preg); |
|
|
|
} |
|
|
|
|
|
|
@ -50,8 +51,7 @@ function ajuster_intertitres($texte, $decalage_ou_niveau = 1, $echappe = 'blockq |
|
|
|
while ($ancien_niveau > 0 and $ancien_niveau <= $niveau_max_recherche){ |
|
|
|
$nouveau_niveau = $ancien_niveau+$decalage; |
|
|
|
if ($nouveau_niveau > 0) { |
|
|
|
$texte = str_replace("<h$ancien_niveau", "<h$nouveau_niveau", $texte); |
|
|
|
$texte = str_replace("</h$ancien_niveau", "</h$nouveau_niveau", $texte); |
|
|
|
$texte = preg_replace('<(\/?)h'.$ancien_niveau.'\b/', '<$1h'.$nouveau_niveau, $texte); |
|
|
|
} |
|
|
|
$ancien_niveau = $ancien_niveau+$increment; |
|
|
|
} |
|
|
|