Text_Wiki
[ class tree: Text_Wiki ] [ index: Text_Wiki ] [ all elements ]

Source for file deflist.php

Documentation is available at deflist.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: deflist.php,v 1.2 2004/03/30 16:47:00 pmjones Exp $
  20.  
  21.  
  22. /**
  23. * This class implements a Text_Wiki_Rule to find source text marked as a
  24. * definition list.  In short, if a line starts with ':' then it is a
  25. * definition list item; another ':' on the same lines indicates the end
  26. * of the definition term and the beginning of the definition narrative.
  27. * The list items must be on sequential lines (no blank lines between
  28. * them) -- a blank line indicates the beginning of a new list.
  29. *
  30. @author Paul M. Jones <pmjones@ciaweb.net>
  31. *
  32. @package Text_Wiki
  33. *
  34. */
  35.  
  36.     
  37.     
  38.     /**
  39.     * 
  40.     * The regular expression used to parse the source text and find
  41.     * matches conforming to this rule.  Used by the parse() method.
  42.     * 
  43.     * @access public
  44.     * 
  45.     * @var string 
  46.     * 
  47.     * @see parse()
  48.     * 
  49.     */
  50.     
  51.     var $regex = '/\n((:).*\n)(?!(:))/Us';
  52.     
  53.     
  54.     /**
  55.     * 
  56.     * Generates a replacement for the matched text.  Token options are:
  57.     * 
  58.     * 'type' =>
  59.     *     'list_start'    : the start of a definition list
  60.     *     'list_end'      : the end of a definition list
  61.     *     'term_start'    : the start of a definition term
  62.     *     'term_end'      : the end of a definition term
  63.     *     'narr_start'    : the start of definition narrative
  64.     *     'narr_end'      : the end of definition narrative
  65.     *     'unknown'       : unknown type of definition portion
  66.     *
  67.     * @access public
  68.     *
  69.     * @param array &$matches The array of matches from parse().
  70.     *
  71.     * @return series of text and delimited tokens marking the different
  72.     *  list text and list elements.
  73.     *
  74.     */
  75.     
  76.     function process(&$matches)
  77.     {
  78.         // the replacement text we will return to parse()
  79.         $return '';
  80.         
  81.         // the list of post-processing matches
  82.         $list = array();
  83.         
  84.         // start the deflist
  85.         $options = array('type' => 'list_start');
  86.         $return .= $this->addToken($options);
  87.         
  88.         // $matches[1] is the text matched as a list set by parse();
  89.         // create an array called $list that contains a new set of
  90.         // matches for the various definition-list elements.
  91.         preg_match_all(
  92.             '/^(:)(.*)?(:)(.*)?$/Ums',
  93.             $matches[1],
  94.             $list,
  95.             PREG_SET_ORDER
  96.         );
  97.         
  98.         // add each term and narrative
  99.         foreach ($list as $key => $val{
  100.             $return .= (
  101.                 $this->addToken(array('type' => 'term_start')) .
  102.                 trim($val[2].
  103.                 $this->addToken(array('type' => 'term_end')) .
  104.                 $this->addToken(array('type' => 'narr_start')) .
  105.                 trim($val[4]
  106.                 $this->addToken(array('type' => 'narr_end'))
  107.             );
  108.         }
  109.         
  110.         
  111.         // end the deflist
  112.         $options = array('type' => 'list_end');
  113.         $return .= $this->addToken($options);
  114.         
  115.         // done!
  116.         return "\n" $return "\n";
  117.     }
  118.     
  119.     
  120.     /**
  121.     * 
  122.     * Renders a token into text matching the requested format.
  123.     * 
  124.     * @access public
  125.     * 
  126.     * @param array $options The "options" portion of the token (second
  127.     *  element).
  128.     * 
  129.     * @return string The text rendered from the token options.
  130.     * 
  131.     */
  132.     
  133.     function renderXhtml($options)
  134.     {
  135.         $type $options['type'];
  136.         $pad "    ";
  137.         
  138.         switch ($type{
  139.         
  140.         case 'list_start':
  141.             return "<dl>\n";
  142.             break;
  143.         
  144.         case 'list_end':
  145.             return "</dl>\n";
  146.             break;
  147.         
  148.         case 'term_start':
  149.             return $pad "<dt>";
  150.             break;
  151.         
  152.         case 'term_end':
  153.             return "</dt>\n";
  154.             break;
  155.         
  156.         case 'narr_start':
  157.             return $pad $pad "<dd>";
  158.             break;
  159.         
  160.         case 'narr_end':
  161.             return "</dd>\n";
  162.             break;
  163.         
  164.         default:
  165.             return '';
  166.         
  167.         }
  168.     }
  169. }
  170. ?>

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