4 * Fonctions utiles pour les wheels SPIP sur les paragraphes
6 * @SPIP\Textwheel\Wheel\SPIP\Fonctions
9 if (!defined('_ECRIRE_INC_VERSION')) {
13 if (!defined('_BALISES_BLOCS')) {
14 define('_BALISES_BLOCS',
15 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style'
20 * Callback de detection des liens qui contiennent des blocks :
21 * dans ce cas il faut traiter le <a> comme un quasi block et fermer/ouvrir les <p> autour du <a>
26 function detecter_liens_blocs(&$t) {
28 // si une balise bloc est dans le liens, on y a aussi ajoute un <p>, il suffit donc de detecter ce dernier
29 if (strpos($t[2], "<p>") !== false) {
30 return "<STOP P>" . $t[1] . "<p>" . $t[2] . "</p>" . $t[3] . "\n<p>";
37 * Callback fermer-para-mano
39 * On refait le preg, à la main
44 function fermer_para_mano(&$t) {
45 # match: ",<p (.*)<(/?)(stop p|address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style)\b,UimsS"
46 # replace: "\n<p "+trim($1)+"</p>\n<$2$3"
48 foreach (array('<p ' => "</p>\n", '<li' => "<br-li/>") as $cut => $close) {
49 if (strpos($t, $cut) !== false) {
50 foreach (explode($cut, $t) as $c => $p) {
56 ",</?(?:stop p|" . _BALISES_BLOCS
. ")\b,S",
58 $pos = strpos($pi, $r[0]);
59 $t .= $cut . str_replace("\n", _AUTOBR
. "\n",
60 ($close ?
rtrim(substr($p, 0, $pos)) : substr($p, 0, $pos))) . $close . substr($p, $pos);
69 if (strpos($t, "<br-li/>") !== false) {
70 $t = str_replace("<br-li/></li>", "</li>", $t); // pour respecter les non-retour lignes avant </li>
71 $t = str_replace("<br-li/><ul>", "<ul>", $t); // pour respecter les non-retour lignes avant <ul>
72 $t = str_replace("<br-li/>", "\n", $t);
75 $t = str_replace(_AUTOBR
. "\n" . "<br", "\n<br", $t); #manque /i
76 $reg = ',(<(p|br|li)\b[^>]*>\s*)' . preg_quote(_AUTOBR
. "\n", ',') . ",iS";
77 $t = preg_replace($reg, '\1' . "\n", $t);