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 / Paragraph.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  3.5 KB  |  146 lines

  1. <?php
  2.  
  3. /**
  4. * Parses for paragraph blocks.
  5. * @category Text
  6. * @package Text_Wiki
  7. * @author Paul M. Jones <pmjones@php.net>
  8. * @license LGPL
  9. * @version $Id: Paragraph.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $
  10. */
  11.  
  12. /**
  13. * Parses for paragraph blocks.
  14. * This class implements a Text_Wiki rule to find sections of the source
  15. * text that are paragraphs.  A para is any line not starting with a token
  16. * delimiter, followed by two newlines.
  17. *
  18. * @category Text
  19. * @package Text_Wiki
  20. * @author Paul M. Jones <pmjones@php.net>
  21. */
  22.  
  23. class Text_Wiki_Parse_Paragraph extends Text_Wiki_Parse {
  24.     
  25.     /**
  26.     * 
  27.     * The regular expression used to find source text matching this
  28.     * rule.
  29.     * 
  30.     * @access public
  31.     * 
  32.     * @var string
  33.     * 
  34.     */
  35.     
  36.     var $regex = "/^.*?\n\n/m";
  37.     
  38.     var $conf = array(
  39.         'skip' => array(
  40.             'blockquote', // are we sure about this one?
  41.             'code',
  42.             'heading',
  43.             'horiz',
  44.             'deflist',
  45.             'table',
  46.             'list',
  47.             'toc'
  48.         )
  49.     );
  50.     
  51.     
  52.     /**
  53.     * 
  54.     * Generates a token entry for the matched text.  Token options are:
  55.     * 
  56.     * 'start' => The starting point of the paragraph.
  57.     * 
  58.     * 'end' => The ending point of the paragraph.
  59.     * 
  60.     * @access public
  61.     *
  62.     * @param array &$matches The array of matches from parse().
  63.     *
  64.     * @return A delimited token number to be used as a placeholder in
  65.     * the source text.
  66.     *
  67.     */
  68.     
  69.     function process(&$matches)
  70.     {
  71.         $delim = $this->wiki->delim;
  72.         
  73.         // was anything there?
  74.         if (trim($matches[0]) == '') {
  75.             return '';
  76.         }
  77.         
  78.         // does the match start with a delimiter?
  79.         if (substr($matches[0], 0, 1) != $delim) { 
  80.             // no.
  81.             
  82.             $start = $this->wiki->addToken(
  83.                 $this->rule, array('type' => 'start')
  84.             );
  85.             
  86.             $end = $this->wiki->addToken(
  87.                 $this->rule, array('type' => 'end')
  88.             );
  89.             
  90.             return $start . trim($matches[0]) . $end;
  91.         }
  92.         
  93.         // the line starts with a delimiter.  read in the delimited
  94.         // token number, check the token, and see if we should
  95.         // skip it.
  96.         
  97.         // loop starting at the second character (we already know
  98.         // the first is a delimiter) until we find another
  99.         // delimiter; the text between them is a token key number.
  100.         $key = '';
  101.         $len = strlen($matches[0]);
  102.         for ($i = 1; $i < $len; $i++) {
  103.             $char = $matches[0]{$i};
  104.             if ($char == $delim) {
  105.                 break;
  106.             } else {
  107.                 $key .= $char;
  108.             }
  109.         }
  110.         
  111.         // look at the token and see if it's skippable (if we skip,
  112.         // it will not be marked as a paragraph)
  113.         $token_type = strtolower($this->wiki->tokens[$key][0]);
  114.         $skip = $this->getConf('skip', array());
  115.         
  116.         if (in_array($token_type, $skip)) {
  117.             // this type of token should not have paragraphs applied to it.
  118.             // return the entire matched text.
  119.             return $matches[0];
  120.         } else {
  121.             
  122.             $start = $this->wiki->addToken(
  123.                 $this->rule, array('type' => 'start')
  124.             );
  125.             
  126.             $end = $this->wiki->addToken(
  127.                 $this->rule, array('type' => 'end')
  128.             );
  129.             
  130.             return $start . trim($matches[0]) . $end;
  131.         }
  132.     }
  133. }
  134. ?>