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.5 2004/03/30 16:47:00 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.     * The regular expression used to find source text matching this
  37.     * rule.
  38.     * 
  39.     * @access public
  40.     * 
  41.     * @var string 
  42.     * 
  43.     */
  44.     
  45.     var $regex = "/^.*?\n\n/m";
  46.     
  47.     
  48.     /**
  49.     * 
  50.     * Generates a token entry for the matched text.  Token options are:
  51.     * 
  52.     * 'start' => The starting point of the paragraph.
  53.     * 
  54.     * 'end' => The endinging point of the paragraph.
  55.     * 
  56.     * @access public
  57.     *
  58.     * @param array &$matches The array of matches from parse().
  59.     *
  60.     * @return delimited token number to be used as a placeholder in
  61.     *  the source text.
  62.     *
  63.     */
  64.     
  65.     function process(&$matches)
  66.     {
  67.         $delim $this->_wiki->delim;
  68.         
  69.         // was anything there?
  70.         if (trim($matches[0]== ''{
  71.             return '';
  72.         }
  73.         
  74.         // does the match start with a delimiter?
  75.         if (substr($matches[0]01!= $delim
  76.             // no.
  77.             $start $this->addToken(array('type' => 'start'));
  78.             $end $this->addToken(array('type' => 'end'));
  79.             return $start trim($matches[0]$end;
  80.         }
  81.         
  82.         // the line starts with a delimiter.  read in the delimited
  83.         // token number, check the token, and see if we should
  84.         // skip it.
  85.         
  86.         // loop starting at the second character (we already know
  87.         // the first is a delimiter) until we find another
  88.         // delimiter; the text between them is a token key number.
  89.         $key '';
  90.         $len strlen($matches[0]);
  91.         for ($i = 1; $i $len$i++{
  92.             $char $matches[0]{$i};
  93.             if ($char == $delim{
  94.                 break;
  95.             else {
  96.                 $key .= $char;
  97.             }
  98.         }
  99.         
  100.         // look at the token and see if it's skippable (if we skip,
  101.         // it will not be marked as a paragraph)
  102.         $token_type $this->_wiki->_tokens[$key][0];
  103.         if (in_array($token_type$this->_conf['skip'])) {
  104.             return $matches[0];
  105.         else {
  106.             $start $this->addToken(array('type' => 'start'));
  107.             $end $this->addToken(array('type' => 'end'));
  108.             return $start trim($matches[0]$end;
  109.         }
  110.     }
  111.     
  112.     
  113.     /**
  114.     * 
  115.     * Renders a token into text matching the requested format.
  116.     * 
  117.     * @access public
  118.     * 
  119.     * @param array $options The "options" portion of the token (second
  120.     *  element).
  121.     * 
  122.     * @return string The text rendered from the token options.
  123.     * 
  124.     */
  125.     
  126.     function renderXhtml($options)
  127.     {
  128.         extract($options)//type
  129.         
  130.         if ($type == 'start'{
  131.             return '<p>';
  132.         }
  133.         
  134.         if ($type == 'end'{
  135.             return "</p>\n\n";
  136.         }
  137.     }
  138. }
  139. ?>

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