Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   PHP (https://www.clubdelphi.com/foros/forumdisplay.php?f=15)
-   -   Etiquetas vB. (https://www.clubdelphi.com/foros/showthread.php?t=28138)

Lepe 14-12-2005 18:08:17

Cita:

Empezado por Migpal
Si Gunman sabía quien le responderia la duda, porque no le manda un Mail en lugar de tener que rogar publicamente que le contesten.

Es una sugerencia......

Si lo hubiera hecho, hubiesemos perdido el excelente mensaje de roman.

¿Hubieses preferido prescindir de este hilo completo? :confused:

saludos

dec 14-12-2005 22:26:15

Hola,

Para quien le pueda interesar, no he podido resistirme a lo siguiente.


Código PHP:

<?php // magic!

/*
    delphi2html PHP class v1.0b

    (w) 2005 David Esperalta Calderón

    Thanks very much to the people of ClubDelphi Forums
    ([url]http://www.clubdelphi.com[/url]) and specially to Román
    from the idea and tutorial. ¡Thanks to all! ;-)

    Comments are welcome in davidesperalta @ gmail.com
    or in the ClubDelphi Forums (see url above)

*/

/*
    // Example usage 1
    //
    $colorize = new delphi2html();
     $file = file('./delphi_unit.pas');
    foreach ($file as $line) $temp .= $line;
     echo $colorize->execute($temp, true, true);

*/

/*
    // Example usage 2
    //
    $colorize = new delphi2html();
    $text = "type\n";
    $text .= " TForm1 = class(TForm)\n";
    $text .= " { Private declarations }\n";
    $text .= " private\n";
    $text .= "    procedure AMethod(param: string);\n";
    $text .= " end;\n";
    echo $colorize->execute($text, true, true);

*/    

class delphi2html {

    
// Style (CSS code)
    //
    
var $css_style =
     
"<style type='text/css'>
         .str { background-color: transparent; color: Green; }
         .idn { background-color: transparent; color: Black; }
         .res { background-color: transparent; color: Navy; font-weight: bold; }
         .com { background-color: transparent; color: Gray; font-style: italic; }
     </style>\n"
;

    
// Reserved keywords in Delphi
    //
    
var $keybords = array (
     
"and""array""as""asm""begin""case""class""const",
     
"constructor""destructor""dispinterface""div""do""downto",
     
"else""end""except""exports""file""finalization""finally",
     
"for""function""goto""if""implementation""in""inherited",
     
"initialization""inline""interface""is""label""library",
     
"mod""nil""not""object""of""or""out""packed""procedure",
     
"program""property""raise""record""repeat""resourcestring",
     
"set""shl""shr""string""then""threadvar""to""try""type",
     
"unit""until""uses""var""while""with""xor""private",
     
"protected""public""published""automated"
    
);

    
// Regular Exp for strings, identifiers and comments tokens.
    //
    
var $reg_exp             "";
    var 
$reg_exp_strings     "('.*?')|";
    var 
$reg_exp_identifiers "([a-z_][a-z0-9_]*)|";
    var 
$reg_exp_comments    "(\{.*?\}|\(\*.*?\*\)|//.*?\n|//.*\$)";

    
// Class constructor.
    //
    
function delphi2html() {

        
$this->reg_exp "#".
         
$this->reg_exp_strings.
         
$this->reg_exp_identifiers.
         
$this->reg_exp_comments ."#si";
    }

    
// Callback function.
    //
    
function replace($matches) {

        switch (
$matches[0])
         {
            case 
$matches[1]: // strings
             
return "<span class='str'>" .$matches[1]. "</span>";
             break;

             case 
$matches[2]: // identifiers
                 
if (in_array($matches[2], $this->keybords))
                    return 
"<span class='res'>" .$matches[2]. "</span>";
                 else
                    return 
"<span class='idn'>" .$matches[2]. "</span>";
                 break;

             case 
$matches[3]: // comments
                 
return "<span class='com'>" .$matches[3]. "</span>";
                 break;
         }
    }

    
// The main public method: execute
    //
    // param: code, string: the delphi source code to colorize.
    // param: add_css_code, boolean: add the CSS code in result.
    // param: add_pre_tags, boolean: add the <pre></pre> HTML tags.
    //
    // return: HTML delphi colorized text.
    //
    
function execute($code$add_css_code true$add_pre_tags true) {

        
$result preg_replace_callback($this->reg_exp,
                    array(
$this'replace'), $code);
        
        if(!
$add_pre_tags) {
            
         if(!
$add_css_code) { return $result; }
         else { return 
$this->css_style $result; }            
        
        } else {
            
         if(!
$add_css_code) { return "<pre>" .$result"</pre>"; }
         else { return 
$this->css_style "<pre>" .$result"</pre>"; }
        
        }            
        
    } 
// function execute

// class delphi2html

?>

Muchas gracias otra vez Román. ;)

[Gunman] 14-12-2005 23:56:08

Hola, disculpa el retraso roman y una vez más disculpas.
Yo no sabia quien me contestaria, lo supe cuando DeC me dijo que Román había creado las etiquetas "delphi", antes de esto no sabía nada.
Muchas gracias, me pongo manos a la obra.

dec 16-12-2005 05:58:54

Hola,

Sobre el tema de las Expresiones Regulares he topado con la página Web en español www.ignside.net, donde se ofrecen unos apuntes sobre PHP que incluyen un apartado acerca de su uso. Lo refiero aquí para ampliar la información tratada en este Hilo. Por si puede interesar a alguien, vaya. ;)

D-MO 16-12-2005 06:30:28

Cita:

Empezado por dec
Por si puede interesar a alguien, vaya. ;)

Siempre ayudando he dec. Gracias por tu informacion de nuevo.
Saludos


La franja horaria es GMT +2. Ahora son las 15:48:15.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi