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 230214 2007-02-19 08:57:14Z mic $
  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.             'box',
  42.             'blockquote',
  43.             'code',
  44.             'heading',
  45.             'center',
  46.             'horiz',
  47.             'deflist',
  48.             'table',
  49.             'list',
  50.             'paragraph',
  51.             'preformatted',
  52.             'toc'
  53.         )
  54.     );
  55.  
  56.  
  57.     /**
  58.      *
  59.      * Generates a token entry for the matched text. Token options are:
  60.      *
  61.      * 'start' => The starting point of the paragraph.
  62.      *
  63.      * 'end' => The ending point of the paragraph.
  64.      *
  65.      * @access public
  66.      *
  67.      * @param array &$matches The array of matches from parse().
  68.      *
  69.      * @return delimited token number to be used as a placeholder in
  70.      *  the source text.
  71.      *
  72.      */
  73.  
  74.     function process(&$matches)
  75.     {
  76.         $delim $this->wiki->delim;
  77.  
  78.         // was anything there?
  79.         if (trim($matches[0]== ''{
  80.             return '';
  81.         }
  82.  
  83.         // does the match start with a delimiter?
  84.         if (substr($matches[0]01!= $delim{
  85.             // no.
  86.  
  87.             $start $this->wiki->addToken(
  88.                 $this->rulearray('type' => 'start')
  89.             );
  90.  
  91.             $end $this->wiki->addToken(
  92.                 $this->rulearray('type' => 'end')
  93.             );
  94.  
  95.             return $start trim($matches[0]$end;
  96.         }
  97.  
  98.         // the line starts with a delimiter.  read in the delimited
  99.         // token number, check the token, and see if we should
  100.         // skip it.
  101.  
  102.         // loop starting at the second character (we already know
  103.         // the first is a delimiter) until we find another
  104.         // delimiter; the text between them is a token key number.
  105.         $key '';
  106.         $len strlen($matches[0]);
  107.         for ($i = 1; $i $len$i++{
  108.             $char $matches[0]{$i};
  109.             if ($char == $delim{
  110.                 break;
  111.             else {
  112.                 $key .= $char;
  113.             }
  114.         }
  115.  
  116.         // look at the token and see if it's skippable (if we skip,
  117.         // it will not be marked as a paragraph)
  118.         $token_type strtolower($this->wiki->tokens[$key][0]);
  119.         $skip $this->getConf('skip'array());
  120.  
  121.         if (in_array($token_type$skip)) {
  122.             // this type of token should not have paragraphs applied to it.
  123.             // return the entire matched text.
  124.             return $matches[0];
  125.         else {
  126.  
  127.             $start $this->wiki->addToken(
  128.                 $this->rulearray('type' => 'start')
  129.             );
  130.  
  131.             $end $this->wiki->addToken(
  132.                 $this->rulearray('type' => 'end')
  133.             );
  134.  
  135.             return $start trim($matches[0]$end;
  136.         }
  137.     }
  138. }
  139. ?>

Documentation generated on Mon, 11 Mar 2019 15:40:30 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.