L’extension WordPress du mois : Google Syntax Highlighter

Par Yohann CIURLIK le 30 avril 2009, 00:27

Je viens de découvrir Google Syntax Highlighter pour .

Cette extension à pour but de faciliter l’intégration de la Syntax Highlighter développée par Alex Gorbatchev. Cette dernière permet de mettre en valeur du code source dans une page . Voici, en exemple, un extrait du code source de la classe PHP Twitter :

<?php
///////////////////////////////////////////
//
// twitterPHP
// version 0.1
// By David Billingham
// david [at] slawcup [dot] com
// http://twitter.slawcup.com/twitter.class.phps
//
//
// Example 1:
//
// $t= new twitter();
// $res = $t->publicTimeline();
// if($res===false){
//   echo "ERROR

"; // echo "
";
//   print_r($t->responseInfo);
//     echo "

";
// }else{
// echo "SUCCESS


";
// echo "

";
//   print_r($res);
//     echo "

";
// }
//
//
// Example 2:
//
// $t= new twitter();
// $t->username='username';
// $t->password='password';
// $res = $t->update('i am testing twitter.class.php');
// if($res===false){
// echo "ERROR


";
// echo "

";
//   print_r($t->responseInfo);
//     echo "

";
// }else{
// echo "SUCCESS


Status Posted";
// }
//
//
... some code here...
sendDirectMessage($user,$text){
$request = 'http://twitter.com/direct_messages/new.xml';
$postargs = 'user='.urlencode($user).'&text='.urlencode($text);
return $this->process($request,$postargs);
}
// internal function where all the juicy curl fun takes place
// this should not be called by anything external unless you are
// doing something else completely then knock youself out.
function process($url,$postargs=false){
$ch = curl_init($url);
if($postargs !== false){
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postargs);
}
if($this->username !== false && $this->password !== false)
curl_setopt($ch, CURLOPT_USERPWD, $this->username.':'.$this->password);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
$response = curl_exec($ch);
$this->responseInfo=curl_getinfo($ch);
curl_close($ch);
if(intval($this->responseInfo['http_code'])==200){
if(class_exists('SimpleXMLElement')){
$xml = new SimpleXMLElement($response);
return $xml;
}else{
return $response;
}
}else{
return false;
}
}
}
?>

Pour obtenir ceci, il suffit de mettre le code entre les balises pre suivantes :

<pre class="c-sharp" name="code">
... some code here ...
</pre>

Ce script fonctionne avec les codes sources suivants :

  • C++ (cpp, c, c++)
  • C# (c#, c-sharp, csharp)
  • CSS (css)
  • Delphi (delphi, pascal)
  • Java (java)
  • Java Script (js, jscript, javascript)
  • PHP (php)
  • Python (py, python)
  • Ruby (rb, ruby, rails, ror)
  • Sql (sql)
  • VB (vb, vb.net)
  • XML/HTML (xml, html, xhtml, xslt)

Les différents principaux navigateurs sont supportés. Le résultat est à la fois très sympa et surtout très pratique. Il est ainsi aisé de faire un copier/coller du code source en question.

Disponible via le site de plugins WordPress

Cet article vous a plu ? Abonnez-vous au blog par mail ou flux RSS : vous recevrez automatiquement les nouveaux billets !


1 Commentaire


1
ArianaHemn13 mai 2009 à 12:11

thans for the tip

Laissez un commentaire

Votre commentaire

inicio