- <?php
- class highlight_html
- {
- var $color_base = '#000000'; //Couleur du texte hors-balises
- var $color_coms = '#008000'; //Couleur des commentaires et scripts
- var $color_tags = '#000099'; //Couleur des tages (a, div, span, img, table...)
- var $color_dels = '#000099'; //Couleur des delimiteurs < et >
- var $color_atts = '#FF9900'; //Couleur des attributs (href, src, class, style...)
- var $color_vals = '#0000FF'; //Couleur des valeurs d'attributs
-
- var $option_egal = TRUE; //Défini si le = prend la couleur de l'attribut, et les " la couleur de la valeur
- var $option_nl2br = TRUE; //Défini si les retours de lignes doivent être remplacés par des <br />
-
- function color_tags($cod)
- {
- $mask = "#([a-zA-Z0-1\-_]+)=(('|\")|)(.*?)(?(3)(\\3)|( |>))#si";
- if (!$this->option_egal) $repl = "<span style='color: {$this->color_atts}'>\\1</span>=\\3<span style='color: {$this->color_vals}'>\\4</span>\\3\\6";
- if ($this->option_egal) $repl = "<span style='color: {$this->color_atts}'>\\1=</span><span style='color: {$this->color_vals}'>\\3\\4\\3</span>\\6";
- return preg_replace($mask,$repl,$cod);
- }
-
- function int_html($match)
- {
- $bals = array('script','style');
- if (empty($match[2])) $match[2] = '';
- $ends = "<span style='color: {$this->color_base}'>";
- return "</span><span style='color: {$this->color_dels}; font-weight: bold'><</span><span style='color: {$this->color_tags}; font-weight: bold'>$match[1]</span>".substr($this->color_tags($match[2]),0,-1)."<span style='color: {$this->color_dels}; font-weight: bold'>></span>".$ends;
- }
-
- function color_html($code)
- {$code = str_replace('<','<',$code);
- $code = str_replace('<!--',"</span><span style='color: {$this->color_coms}'><!--",$code);
- $code = "<span style='color: {$this->color_base}'>".preg_replace_callback("#<([/a-zA-Z0-9!\?]+)(( [^>]*)?>)#si",array(&$this,'int_html'),$code)."</span>";
- if ($this->option_nl2br) $code = nl2br($code);
- return $code;
- }
- }
- ?>
<?php
class highlight_html
{
var $color_base = '#000000'; //Couleur du texte hors-balises
var $color_coms = '#008000'; //Couleur des commentaires et scripts
var $color_tags = '#000099'; //Couleur des tages (a, div, span, img, table...)
var $color_dels = '#000099'; //Couleur des delimiteurs < et >
var $color_atts = '#FF9900'; //Couleur des attributs (href, src, class, style...)
var $color_vals = '#0000FF'; //Couleur des valeurs d'attributs
var $option_egal = TRUE; //Défini si le = prend la couleur de l'attribut, et les " la couleur de la valeur
var $option_nl2br = TRUE; //Défini si les retours de lignes doivent être remplacés par des <br />
function color_tags($cod)
{
$mask = "#([a-zA-Z0-1\-_]+)=(('|\")|)(.*?)(?(3)(\\3)|( |>))#si";
if (!$this->option_egal) $repl = "<span style='color: {$this->color_atts}'>\\1</span>=\\3<span style='color: {$this->color_vals}'>\\4</span>\\3\\6";
if ($this->option_egal) $repl = "<span style='color: {$this->color_atts}'>\\1=</span><span style='color: {$this->color_vals}'>\\3\\4\\3</span>\\6";
return preg_replace($mask,$repl,$cod);
}
function int_html($match)
{
$bals = array('script','style');
if (empty($match[2])) $match[2] = '';
$ends = "<span style='color: {$this->color_base}'>";
return "</span><span style='color: {$this->color_dels}; font-weight: bold'><</span><span style='color: {$this->color_tags}; font-weight: bold'>$match[1]</span>".substr($this->color_tags($match[2]),0,-1)."<span style='color: {$this->color_dels}; font-weight: bold'>></span>".$ends;
}
function color_html($code)
{$code = str_replace('<','<',$code);
$code = str_replace('<!--',"</span><span style='color: {$this->color_coms}'><!--",$code);
$code = "<span style='color: {$this->color_base}'>".preg_replace_callback("#<([/a-zA-Z0-9!\?]+)(( [^>]*)?>)#si",array(&$this,'int_html'),$code)."</span>";
if ($this->option_nl2br) $code = nl2br($code);
return $code;
}
}
?>