Coloration Syntaxique

Télécharger le script ! - mod phpBB

<!--
  Bienvenue sur le Syntax Highlighter
-->

<?php
$dvp
=true;

  function 
getmicrotime(){
    list(
$usec$sec) = explode(' ',microtime());
    return ((float)
$usec + (float)$sec);
  }
?>

<html>
<head>
    <title>Syntax Highlighter</title>
<script language="JavaScript" type="text/javascript">
<!--//
    window.status = 'Syntax Highlighter !';
    
    function do_something() {
        var tablo = new Array('abc',23);
        with (document.body) {
            style.backgroundColor = '#000';
        }
        alert(navigator.userAgent);
    }
//-->
</script>
<style type="text/css">
/*
.code .keyword {color: black; font-weight: bold;}
.code .typevar {color:#066;}
.code .text {color:#004;}
.code .string {color:#00c;}
.code .comment {color:#ff7f00; font-style:italic;}
.code .doc {color:#aa4400; font-style:normal; }
.code .symbol {color:black;}
.code .number {color:#20d;}
.code .preproc {color:#553f00; background:#ffffa8;}
.code .function {color:#7f007f;}
*/
/* ADA */
.code .adakeyword {color: black; font-weight: bold;}
.code .adatext {color:#004;}
.code .adastring {color:#00c;}
.code .adacomment {color:#ff7f00; font-style:italic;}
.code .adasymbol {color:black;}
.code .adanumber {color:#20d;}
.code .adapreproc {color:#553f00; background:#ffffa8;}

/* C/C++ */
.code .ckeyword,
.code .ctypevar {color: #008; font-weight: bold;}
.code .ctext {color:black;}
.code .cstring {color:#808;}
.code .ccomment {color:#060; font-style:italic;}
.code .csymbol {color:black; font-weight: bold;}
.code .cnumber {color:#088;}
.code .cpreproc {color:#880;}
.code .cfunction {color:#654;}

/* Casio */
.code .casiokeyword {color: #03f;}
.code .casiotypevar {color:#066;}
.code .casiofunction {color:#036;}
.code .casiotext {color: black;}
.code .casiostring {color:#9C309C;}
.code .casiocomment {color:#639A31;}
.code .casiosymbol {color:black;}
.code .casionumber {color:#440;}

/* C# */
.code .csharpkeyword,
.code .csharptypevar {color: #008; font-weight: bold;}
.code .csharptext {color:black;}
.code .csharpstring {color:#808;}
.code .csharpcomment {color:#060; font-style:italic;}
.code .csharpsymbol {color:black; font-weight: bold;}
.code .csharpnumber {color:#088;}

/* CSS */
.code .csskeyword {color: black; font-weight: normal;}
.code .csstext { color: darkred; }
.code .csscomment {color:#080; }
.code .csssymbol {color:darkblue; }
.code .cssnumber {color:#808;}
.code .cssfunction { color: #808; }

/* DELPHI */
.code .delphikeyword {color: black; font-weight: bold;}
.code .delphitypevar {color: #606;}
.code .delphitext {color:#606;}
.code .delphistring {color:#008;}
.code .delphicomment {color:#ff7f00; font-style:italic;}
.code .delphisymbol {color:black; font-weight: bold;}
.code .delphinumber {color:#008;}
.code .delphipreproc {color:#553f00; background:#ffffa8;}
.code .delphifunction {color:#606;}

/* HTML */
.code .htmlkeyword {color:#008;}
.code .htmltext {color:black;}
.code .htmlstring {color:#808;}
.code .htmlcomment {color:#ff7f00; font-style:italic;}
.code .htmlsymbol {color:black;}
.code .htmlnumber {color:#808;}
.code .htmlpreproc {color:#654;}
.code .htmlfunction {color:#088;}

/* INI */
.code .initext {color:#004;}
.code .inistring {color:#00c;}
.code .inicomment {color:#ff7f00; font-style:italic;}
.code .inisymbol {color:black;}
.code .ininumber {color:#20d;}
.code .inipreproc {color:#553f00; background:#ffffa8;}

/* JAVA */
.code .javakeyword {color: #707; font-weight: bold;}
.code .javatypevar {color: #707; font-weight: bold;}
.code .javatext {color: black;}
.code .javastring {color:#00c;}
.code .javacomment {color:#C80; font-style:italic;}
.code .javadoc {color:#395DBD; font-style:normal; }
.code .javasymbol {color:black;}
.code .javanumber {color:black;}

/* JAVASCRIPT */
.code .javascriptkeyword {color: #008; font-weight: bold;}
.code .javascripttypevar {color:#840;}
.code .javascripttext {color:black;}
.code .javascriptstring {color:#808;}
.code .javascriptcomment {color:#060; font-style:italic;}
.code .javascriptsymbol {color:black;}
.code .javascriptnumber {color:#088;}
.code .javascriptfunction {color:#048;}

/* LUA */
.code .luakeyword {color: #c5c;}
.code .luatypevar {color:#006;}
.code .luatext {color:black;}
.code .luastring {color:#777;}
.code .luacomment {color:#0a0;}
.code .luadoc {color:#0a0; }
.code .luasymbol {color:black;}
.code .luanumber {color:#20d;}
.code .luapreproc {color:#006;}
.code .luafunction {color:#007f7f;}

/* OCAML */
.code .ocamlkeyword {color: black; font-weight: bold;}
.code .ocamltypevar {color:#066;}
.code .ocamltext {color:#004;}
.code .ocamlstring {color:#00c;}
.code .ocamlcomment {color:#ff7f00; font-style:italic;}
.code .ocamlsymbol {color:black;}
.code .ocamlnumber {color:#20d;}
.code .ocamlpreproc {color:#553f00; background:#ffffa8;}

/* PHP */
a.phpfunction:link, A.phpfunction:visited {color:#005177; font-weight:bold; text-decoration:none;}
a.phpfunction:hover {color:#c33; text-decoration:underline;}

/* Shell */
.code .shellkeyword {color:#A520F7; font-weight: bold;}
.code .shelltext {color:#004;}
.code .shellstring {color:#094A48;}
.code .shellcomment {color:#B52021; font-style:italic;}
.code .shellsymbol {color:black;}
.code .shellnumber {color:black;}
.code .shelltext {color:black;}
.code .shellfunction {color:#20d;}
.code .shellpreproc {color:#5A9EA5;}

/* SQL */
.code .sqlkeyword {color: black; font-weight: bold;}
.code .sqltext {color:#004;}
.code .sqlstring {color:#00c;}
.code .sqlcomment {color:#ff7f00; font-style:italic;}
.code .sqlsymbol {color:black;}
.code .sqlnumber {color:#20d;}
.code .sqlfunction {color:#7f007f;}

/* VB */
.code .vbkeyword {color: #03f;}
.code .vbtypevar {color:#36c;}
.code .vbtext {color: black;}
.code .vbstring {color:#9C309C;}
.code .vbcomment {color:#639A31;}
.code .vbsymbol {color:black;}
.code .vbnumber {color:black;}

*[class="code"] { line-height : 1em }
.code {
    border: 1px inset #a1a4b2;
    padding: 6px;
    color: #000;
    font-size: 11px;
    overflow: auto;
    background-color: #e1e4f2;
    /* Pour colorer la gauche (les nombres) différemment du reste, si addLignes
    background-image: url('gauche.gif');
    background-attachment: left;
    background-repeat: repeat-y;
    */
}

.codeheader {
    border-bottom:1px dashed #966;
    margin-bottom:5px;
    font-weight:bold;
    font-size: 11px;
}

/* ***Navigation*** http://css.maxdesign.com.au/listamatic/horizontal19.htm */
#navcontainer { margin-left: auto; margin-right: auto; margin-bottom: 20px; border-top: 1px solid #999; z-index: 1; }
#navcontainer ul { list-style-type: none; text-align: center; margin-top: -8px; padding: 0; position: relative; z-index: 2; }
#navcontainer li { display: inline; text-align: center; margin: 0 5px; }
#navcontainer li a { padding: 1px 7px; color: #666; background-color: #fff; border: 1px solid #ccc; text-decoration: none; }
#navcontainer li a:hover { color: #000; background: #def; border: 1px solid #9ab; }
#navcontainer li a#current { color: #000; background: #abc; border: 1px solid #678; }
</style>
</head>
<body>
<h2>Coloration Syntaxique</h2>

<p><a href="http://iubito.developpez.com/php/formatcode.zip">Télécharger le script !</a> -
<a href="http://lycee.h.free.fr/info/mods_phpbb2.php">mod phpBB</a></p>


<?php
$lang 
'';
if (isset(
$_GET['lang']))
    
$lang $_GET['lang'];
if (isset(
$_POST['lang']))
    
$lang $_POST['lang'];
$code '';
if (isset(
$_POST['code']))
    
$code stripslashes($_POST['code']);

$list = array('','Ada','C','Casio','CSharp','CSS','Delphi','HTML','Ini','Java','Javascript','Lua','OCaml','PHP','Shell','SQL','VB');
?>

<div id="navcontainer">
<ul id="navlist">

<?php
foreach($list as $k=>$l)
{
    echo 
'<li'.($lang==$l?' id="active"':'').'><a href="?lang='.$l.'"'
        
.($lang==$l?' id="current"':'').'>'.($l!=''?$l:'Accueil').'</a></li>';
    if (
$k == 7) {
        echo 
"</ul></div>\n<div id=\"navcontainer\"><ul id=\"navlist\">";
    }
}
?>

</ul>
</div>


<?php
    $testdir 
$dvp?'SyntaxHighlightTest/':'PHPmyBrowser/classes/SyntaxHighlight/test/';
    
$time_start getmicrotime();
    
$compteur_total 0;
    
    @
set_time_limit(15);
    include(
$dvp?'SyntaxHighlight/bbcode.php':'PHPmyBrowser/classes/bbcode.php');
    
    if (
$code == '')
    {
        
$default false;
        switch(
$lang)
        {
            case 
'Ada':
                
$code implode(""file($testdir.'Test.adb'));
                break;
            case 
'C':
                
$code implode(""file($testdir.'Test.cpp'));
                break;
            case 
'Casio':
                
$code implode(""file($testdir.'Test.casio'));
                break;
            case 
'CSharp':
                
$code implode(""file($testdir.'Test.csharp'));
                break;
            case 
'CSS':
                
$code implode(""file($testdir.'Test.css'));
                break;
            case 
'Delphi':
                
$code implode(""file($testdir.'Test.pas'));
                break;
            case 
'HTML':
                
$code implode(""file('formatcode.php'));
                break;
            case 
'Ini':
                
$code implode(""file($testdir.'Test.ini'));
                break;
            case 
'Java':
                
$code implode(""file($testdir.'Test.java'));
                break;
            case 
'Javascript':
                
$code implode(""file($testdir.'Test.js'));
                break;
            case 
'Lua':
                
$code implode(""file($testdir.'Test.mys'));
                break;
            case 
'OCaml':
                
$code implode(""file($testdir.'Test.ml'));
                break;
            case 
'PHP':
                
$code implode(""file('formatcode.php'));
                break;
            case 
'Shell':
                
$code implode(""file($testdir.'Test.sh'));
                break;
            case 
'SQL':
                
$code implode(""file($testdir.'Test.sql'));
                break;
            case 
'VB':
                
$code implode(""file($testdir.'Test.vb'));
                break;
            default:
                
$default true;
                
$lang 'C';
                
$code "#include <stdio.h>\n\nvoid main(void)\n{\n    printf(\"Hello \\\"World!\");\n}";
                break;
        }
    }
    
    
$c = new SyntaxHighlight($lang$code);
    
$c->pathLanguages $dvp?'SyntaxHighlight':'/www/PHPmyBrowser/classes/SyntaxHighlight';
    
$c->addLineNumbers = isset($_POST['addLine']);
    
$c->optimiseSize = isset($_POST['optimise']);
    
$ret $c->colorize();
    
$time_end getmicrotime();
    
$time $time_end $time_start;
    
    echo 
'<blockquote class="code"><code><nobr>'.$ret.'</nobr></code></blockquote>';
    
$compteur_total += substr_count($ret,"\n");
    
    
?>

<div align="center" style="margin:30px;">
<?=strlen($ret)?>
octets
<br />
<?=($compteur_total+1)?>
lignes g&eacute;n&eacute;r&eacute;es en
<?=round($time,5)?>
secondes,<br />
soit une vitesse de
<?=round($compteur_total/$time)?>
lignes par seconde<br /><br />
<font size="-2">
<?=$_SERVER['SERVER_SOFTWARE']?>
</font></div>
<hr />
<form method="POST">
Texte &agrave; analyser:<br />
<textarea name="code" cols="80" rows="20">
<?php
    
print(htmlentities($code));
?>
</textarea>
<br />
Langage : <select name="lang">

<?php
foreach($list as $l)
{
    echo 
'<option value="'.$l.'"'.($lang==$l?'" selected="selected"':'').'>'.$l.'</option>';
}
?>

</select><br />
<input type="checkbox" name="optimise"
<?php echo isset($_POST['optimise'])?'checked="checked"':''?>
id="optimise" />
<label for="optimise">Optimiser la taille (plus long)</label>
<br />
<input type="checkbox" name="addLine"
<?php echo isset($_POST['addLine'])?'checked="checked"':''?>
id="addLine" />
<label for="addLine">Ajouter les numéros de ligne</label>
<br />
<input type="submit" value="analyser" />
</form>

</body>
</html>
104917 octets
393 lignes générées en 0.04017 secondes,
soit une vitesse de 9759 lignes par seconde

Apache/2.4.59 (Debian)

Texte à analyser:

Langage :