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

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