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. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at                              |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Paul M. Jones <pmjones@ciaweb.net>                          |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: paragraph.php,v 1.4 2004/03/25 14:55:17 pmjones Exp $
  20.  
  21.  
  22. /**
  23. * This class implements a Text_Wiki rule to find sections of the source
  24. * text that are paragraphs.  A para is any line not starting with a token
  25. * delimiter, followed by two newlines.
  26. *
  27. @author Paul M. Jones <pmjones@ciaweb.net>
  28. *
  29. @package Text_Wiki
  30. *
  31. */
  32.  
  33.     
  34.     
  35.     /**
  36.     * 
  37.     * The regular expression used to find source text matching this
  38.     * rule.
  39.     * 
  40.     * @access public
  41.     * 
  42.     * @var string 
  43.     * 
  44.     */
  45.     
  46.     function Text_Wiki_Rule_paragraph(&$obj$name)
  47.     {
  48.         parent::Text_Wiki_Rule($obj$name);
  49.         //$this->regex = "/^(?!{$this->_wiki->delim}).*?\n\n/m";
  50.         $this->regex = "/^.*?\n\n/m";
  51.         $this->_conf =$this->_wiki->rules[$name]['conf'];
  52.     }
  53.     
  54.     /**
  55.     * 
  56.     * Generates a token entry for the matched text.  Token options are:
  57.     * 
  58.     * 'start' => The starting point of the paragraph.
  59.     * 
  60.     * 'end' => The endinging point of the paragraph.
  61.     * 
  62.     * @access public
  63.     *
  64.     * @param array &$matches The array of matches from parse().
  65.     *
  66.     * @return delimited token number to be used as a placeholder in
  67.     *  the source text.
  68.     *
  69.     */
  70.     
  71.     function process(&$matches)
  72.     {
  73.         $delim $this->_wiki->delim;
  74.         
  75.         // was anything there?
  76.         if (trim($matches[0]== ''{
  77.             return '';
  78.         }
  79.         
  80.         // does the match start with a delimiter?
  81.         if (substr($matches[0]01!= $delim
  82.             // no.
  83.             $start $this->addToken(array('type' => 'start'));
  84.             $end $this->addToken(array('type' => 'end'));
  85.             return $start trim($matches[0]$end;
  86.         }
  87.         
  88.         // the line starts with a delimiter.  read in the delimited
  89.         // token number, check the token, and see if we should
  90.         // skip it.
  91.         
  92.         // loop starting at the second character (we already know
  93.         // the first is a delimiter) until we find another
  94.         // delimiter; the text between them is a token key number.
  95.         $key '';
  96.         $len strlen($matches[0]);
  97.         for ($i = 1; $i $len$i++{
  98.             $char $matches[0]{$i};
  99.             if ($char == $delim{
  100.                 break;
  101.             else {
  102.                 $key .= $char;
  103.             }
  104.         }
  105.         
  106.         // look at the token and see if it's skippable (if we skip,
  107.         // it will not be marked as a paragraph)
  108.         $token_type $this->_wiki->_tokens[$key][0];
  109.         if (in_array($token_type$this->_conf['skip'])) {
  110.             return $matches[0];
  111.         else {
  112.             $start $this->addToken(array('type' => 'start'));
  113.             $end $this->addToken(array('type' => 'end'));
  114.             return $start trim($matches[0]$end;
  115.         }
  116.     }
  117.     
  118.     
  119.     /**
  120.     * 
  121.     * Renders a token into text matching the requested format.
  122.     * 
  123.     * @access public
  124.     * 
  125.     * @param array $options The "options" portion of the token (second
  126.     *  element).
  127.     * 
  128.     * @return string The text rendered from the token options.
  129.     * 
  130.     */
  131.     
  132.     function renderXhtml($options)
  133.     {
  134.         extract($options)//type
  135.         
  136.         if ($type == 'start'{
  137.             return '<p>';
  138.         }
  139.         
  140.         if ($type == 'end'{
  141.             return "</p>\n\n";
  142.         }
  143.     }
  144. }
  145. ?>

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