Nom de la contribution : Coloration syntaxique des "diff"
Description : Permet de colorer les diff (générés avec la commande Unix
diff)
Page de discussions :
ColorationSyntaxiqueDiff
Type de contribution : coloration syntaxique
Fonctionne avec :
WikiNi > 0.4.1rc (en principe, testé sous 0.5.0-dev)
Intégration technique : copier le code fourni dans un fichier coloration_diff.php à placer dans le répertoire
/formatters
Mainteneur :
LordFarquaad
Licence : GPL
Dernière version : 0.2.0
Dernière livraison : 2005-11-28
Accès au code et mise en oeuvre :
ColorationSyntaxiqueDiff
Démonstration :
TestColorationSyntaxiqueDiff
Intégration au projet WikiNi :
Bugs :
- problème avec le caractères d'échappement antislash (\), le paramètre PCRE e et la fonction stripslashes() - version complètement révisée -- LordFarquaad
NB.: cette coloration se distingue des autres par le fait qu'elle n'utilise pas la classe
HighLighter??. En effet,
diff travaille ligne par ligne, et il était donc inutile de se complique la vie avec ça. Pour l'instant, elle utilise tout de même
preg_replace, ce qui semble efficace et bien fonctionner. Comme beaucoup de gens fournissent de temps en temps des diff sur
WikiNiPointNet, cette contribution a été mise en oeuvre directement sur le site (d'où la page de test).
Code source de la coloration: (à placer dans un fichier
/formatters/coloration_diff.php)
<?php
/**
* coloration WikiNi pour les diff
*
* @version $Id: coloration_diff.php,v 0.2.0 2005/11/28 01:25:00 lordfarquaad Exp $
* @author Didier Loiseau
* @copyright 2005 Didier Loiseau
* @license This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
echo '<pre>';
foreach (explode("\n", str_replace("\r", '', $text)) as $line)
{
$open = '<span style="color: #';
$close = '</span>';
if (preg_match('/^[<-].*$/S', $line))
{
$open .= '6a5acd;">';
}
elseif (preg_match('/^[>+].*$/S', $line))
{
$open .= '008b8b;">';
}
elseif (preg_match('/^diff.*$/S', $line))
{
$open .= '2e8b57; font-weight: bold;">';
}
elseif (preg_match('/^(@@|[0-9]).*$/S', $line))
{
$open .= 'a52a2a; font-weight: bold;">';
}
else
{
$open = $close = '';
}
echo $open, htmlentities($line), "\n", $close;
}
echo '</pre>';
?>