[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/bundled-libs/Text/Wiki/Parse/Default/ -> Code.php (source)

   1  <?php
   2  // $Id: Code.php,v 1.1 2005/01/31 15:46:52 pmjones Exp $
   3  
   4  
   5  /**
   6  * 
   7  * This class implements a Text_Wiki_Parse to find sections marked as code
   8  * examples.  Blocks are marked as the string <code> on a line by itself,
   9  * followed by the inline code example, and terminated with the string
  10  * </code> on a line by itself.  The code example is run through the
  11  * native PHP highlight_string() function to colorize it, then surrounded
  12  * with <pre>...</pre> tags when rendered as XHTML.
  13  *
  14  * @author Paul M. Jones <pmjones@ciaweb.net>
  15  *
  16  * @package Text_Wiki
  17  *
  18  */
  19  
  20  class Text_Wiki_Parse_Code extends Text_Wiki_Parse {
  21      
  22      
  23      /**
  24      * 
  25      * The regular expression used to find source text matching this
  26      * rule.
  27      * 
  28      * @access public
  29      * 
  30      * @var string
  31      * 
  32      */
  33      
  34      var $regex = '/^(\<code( .+)?\>)\n(.+)\n(\<\/code\>)(\s|$)/Umsi';
  35      
  36      
  37      /**
  38      * 
  39      * Generates a token entry for the matched text.  Token options are:
  40      * 
  41      * 'text' => The full matched text, not including the <code></code> tags.
  42      * 
  43      * @access public
  44      *
  45      * @param array &$matches The array of matches from parse().
  46      *
  47      * @return A delimited token number to be used as a placeholder in
  48      * the source text.
  49      *
  50      */
  51      
  52      function process(&$matches)
  53      {
  54          // are there additional attribute arguments?
  55          $args = trim($matches[2]);
  56          
  57          if ($args == '') {
  58              $options = array(
  59                  'text' => $matches[3],
  60                  'attr' => array('type' => '')
  61              );
  62          } else {
  63              // get the attributes...
  64              $attr = $this->getAttrs($args);
  65              
  66              // ... and make sure we have a 'type'
  67              if (! isset($attr['type'])) {
  68                  $attr['type'] = '';
  69              }
  70              
  71              // retain the options
  72              $options = array(
  73                  'text' => $matches[3],
  74                  'attr' => $attr
  75              );
  76          }
  77          
  78          return $this->wiki->addToken($this->rule, $options) . $matches[5];
  79      }
  80  }
  81  ?>


Généré le : Sat Nov 24 09:00:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics