home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Text / Wiki / Parse / Default / Code.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  2.3 KB  |  100 lines

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