// 2007/08/04 00:52 / 86.220.199.82

Permettre d'ajouter à la demande une Table des matières automatique.

Code


Voici les modifications à apporter à une version 2.21 :
$CONTENT = preg_replace('/^!!!(.*)(\n)/Um', '<h1>$1</h1>$2', $CONTENT);
$CONTENT = preg_replace('/^!!(.*)(\n)/Um', '<h2>$1</h2>$2', $CONTENT);
$CONTENT = preg_replace('/^!(.*)(\n)/Um', '<h3>$1</h3>$2', $CONTENT);

par
$CONTENT = preg_replace('/^!!!(.*)$/Um', '<a name="$1"><h1>$1</h1></a>', $CONTENT);
$CONTENT = preg_replace('/^!!(.*)$/Um', '<a name="$1"><h2>$1</h2></a>', $CONTENT);
$CONTENT = preg_replace('/^!(.*)$/Um', '<a name="$1"><h3>$1</h3></a>', $CONTENT);

$CONTENT = substr($CONTENT, 6, strlen($CONTENT) - 6);

ajouter :
// TOC

if (strpos($CONTENT,"TOC"))

{

   $CONTENT = str_replace("TOC","",$CONTENT);

   $nbAncres = preg_match_all('/<a name="(.+)">(.+)<\/a>/Ums',$CONTENT,$matches_ancres);

   //~ print "<pre>".htmlentities(var_dump($matches_ancres,TRUE))."</pre>"; //DBG

   $toc = "<div id=toc>";

   for ($i=0;$i<$nbAncres;$i++) $toc .= '<a href="#'.$matches_ancres[1][$i].'">'.$matches_ancres[2][$i].'</a> ';

   $toc .= "</div>";

}

else

   $toc = "";

$html = preg_replace('/86.220.199.82/', $_SERVER['REMOTE_ADDR'], $html);

ajouter
$html = str_replace('', $toc, $html);


<td id="mainContent" colspan="3">

ajouter :
{TOC
}

/* Table Of Content */
#toc {
	 border: 1px dashed #11141A;
	 float:right;
	 padding-right: 2em;
}
#toc h1 {
	 font-size: 10px;
	 padding-left: .5em;
}
#toc h2 {
	 font-size: 9px;
	 padding-left: 1.5em;
}
#toc h3 {
	 font-size: 8px;
	 padding-left: 2em;
}



Todo


TOC

<a name="Titre"><h1>Titre</h1></a>

// 2007/08/04 00:52 / 86.220.199.82
TOC
Permettre d'ajouter à la demande une Table des matières automatique.

Code


Voici les modifications à apporter à une version 2.21 :
$CONTENT = preg_replace('/^!!!(.*)(\n)/Um', '<h1>$1</h1>$2', $CONTENT);
$CONTENT = preg_replace('/^!!(.*)(\n)/Um', '<h2>$1</h2>$2', $CONTENT);
$CONTENT = preg_replace('/^!(.*)(\n)/Um', '<h3>$1</h3>$2', $CONTENT);

par
$CONTENT = preg_replace('/^!!!(.*)$/Um', '<a name="$1"><h1>$1</h1></a>', $CONTENT);
$CONTENT = preg_replace('/^!!(.*)$/Um', '<a name="$1"><h2>$1</h2></a>', $CONTENT);
$CONTENT = preg_replace('/^!(.*)$/Um', '<a name="$1"><h3>$1</h3></a>', $CONTENT);

$CONTENT = substr($CONTENT, 6, strlen($CONTENT) - 6);

ajouter :
// TOC

if (strpos($CONTENT,"TOC"))

{

   $CONTENT = str_replace("TOC","",$CONTENT);

   $nbAncres = preg_match_all('/<a name="(.+)">(.+)<\/a>/Ums',$CONTENT,$matches_ancres);

   //~ print "<pre>".htmlentities(var_dump($matches_ancres,TRUE))."</pre>"; //DBG

   $toc = "<div id=toc>";

   for ($i=0;$i<$nbAncres;$i++) $toc .= '<a href="#'.$matches_ancres[1][$i].'">'.$matches_ancres[2][$i].'</a> ';

   $toc .= "</div>";

}

else

   $toc = "";

$html = preg_replace('/86.220.199.82/', $_SERVER['REMOTE_ADDR'], $html);

ajouter
$html = str_replace('', $toc, $html);


<td id="mainContent" colspan="3">

ajouter :



/* Table Of Content */
#toc {
	 border: 1px dashed #11141A;
	 float:right;
	 padding-right: 2em;
}
#toc h1 {
	 font-size: 10px;
	 padding-left: .5em;
}
#toc h2 {
	 font-size: 9px;
	 padding-left: 1.5em;
}
#toc h3 {
	 font-size: 8px;
	 padding-left: 2em;
}



Todo


TOC

<a name="Titre"><h1>Titre</h1></a>