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

Documentation generated on Mon, 11 Mar 2019 13:56:10 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.