Text_Wiki
[ class tree: Text_Wiki ] [ index: Text_Wiki ] [ all elements ]

Source for file Paragraph.php

Documentation is available at Paragraph.php

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

Documentation generated on Mon, 11 Mar 2019 14:55:48 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.