GeSHi
(→Przykład) |
(→Przykład) |
||
| Linia 12: | Linia 12: | ||
if ($handle = opendir($path)) { | if ($handle = opendir($path)) { | ||
while (false !== ($file = readdir($handle))) { // Loop over the directory. | while (false !== ($file = readdir($handle))) { // Loop over the directory. | ||
| − | if(is_dir($file)) continue;// Drop anything that is a directory, cause we want files only | + | if(is_dir($file)) continue; |
| − | if( ".php" == substr($file, strrpos($file, "."),4)) // process only .php files | + | // Drop anything that is a directory, cause we want files only |
| + | if( ".php" == substr($file, strrpos($file, "."),4)) | ||
| + | // process only .php files | ||
{ | { | ||
$lang_list[]= substr($file, 0, strrpos($file, ".")); | $lang_list[]= substr($file, 0, strrpos($file, ".")); | ||
| Linia 21: | Linia 23: | ||
closedir($handle); | closedir($handle); | ||
} | } | ||
| − | sort($lang_list); //sort the output, i like ordered lists in Wiki Version page :) | + | sort($lang_list); |
| + | //sort the output, i like ordered lists in Wiki Version page :) | ||
return $lang_list; | return $lang_list; | ||
} | } | ||
| Linia 31: | Linia 34: | ||
| − | <php> | + | <php>function geshi_list_languages ( $path = 'geshi/' ) |
| − | function geshi_list_languages ( $path = 'geshi/' ) | + | |
{ | { | ||
$lang_list = array(); | $lang_list = array(); | ||
if ($handle = opendir($path)) { | if ($handle = opendir($path)) { | ||
while (false !== ($file = readdir($handle))) { // Loop over the directory. | while (false !== ($file = readdir($handle))) { // Loop over the directory. | ||
| − | if(is_dir($file)) continue; | + | if(is_dir($file)) continue; |
| − | if( ".php" == substr($file, strrpos($file, "."),4)) // process only .php files | + | // Drop anything that is a directory, cause we want files only |
| + | if( ".php" == substr($file, strrpos($file, "."),4)) | ||
| + | // process only .php files | ||
{ | { | ||
$lang_list[]= substr($file, 0, strrpos($file, ".")); | $lang_list[]= substr($file, 0, strrpos($file, ".")); | ||
| Linia 46: | Linia 50: | ||
closedir($handle); | closedir($handle); | ||
} | } | ||
| − | sort($lang_list); //sort the output, i like ordered lists in Wiki Version page :) | + | sort($lang_list); |
| + | //sort the output, i like ordered lists in Wiki Version page :) | ||
return $lang_list; | return $lang_list; | ||
} | } | ||
</php> | </php> | ||
Wersja z 14:51, 16 cze 2006
Opis
GeSHi to generator podświetlenia składni - czyli jak masz jakiś kod, to, umieszczając go w odpowiednich dla danego języka w jakim zostął napsiany tagach, zostanie podświetlony - koloryzowany.
Przykład
Pewnie dla niektórych opis to czarna magia, więc dla nich jakże prosty przykład.
Mamy plik napisany w PHP, normalnie bysmy go wstawili w znacznik >pre< jakis kod >/pre< i byśmy uzyskali żródło na szarym tle.
function geshi_list_languages ( $path = 'geshi/' )
{
$lang_list = array();
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) { // Loop over the directory.
if(is_dir($file)) continue;
// Drop anything that is a directory, cause we want files only
if( ".php" == substr($file, strrpos($file, "."),4))
// process only .php files
{
$lang_list[]= substr($file, 0, strrpos($file, "."));
}
}
closedir($handle);
}
sort($lang_list);
//sort the output, i like ordered lists in Wiki Version page :)
return $lang_list;
}
Zamiast tego dajemy zanczniki >php< jakiś kod >/php<, czyli ten, w jamim jest napisany. W efekcie mamy ładny text.
<php>function geshi_list_languages ( $path = 'geshi/' ) { $lang_list = array(); if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { // Loop over the directory. if(is_dir($file)) continue;
// Drop anything that is a directory, cause we want files only
if( ".php" == substr($file, strrpos($file, "."),4))
// process only .php files
{ $lang_list[]= substr($file, 0, strrpos($file, ".")); } }
closedir($handle); } sort($lang_list);
//sort the output, i like ordered lists in Wiki Version page :)
return $lang_list; } </php>