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. // $Id: Deflist.php,v 1.3 2004/09/25 19:05:13 pmjones Exp $
  3.  
  4.  
  5. /**
  6. * 
  7. * This class implements a Text_Wiki_Parse to find source text marked as a
  8. * definition list.  In short, if a line starts with ':' then it is a
  9. * definition list item; another ':' on the same lines indicates the end
  10. * of the definition term and the beginning of the definition narrative.
  11. * The list items must be on sequential lines (no blank lines between
  12. * them) -- a blank line indicates the beginning of a new list.
  13. *
  14. * @author Paul M. Jones <pmjones@ciaweb.net>
  15. *
  16. * @package Text_Wiki
  17. *
  18. */
  19.  
  20.     
  21.     
  22.     /**
  23.     * 
  24.     * The regular expression used to parse the source text and find
  25.     * matches conforming to this rule.  Used by the parse() method.
  26.     * 
  27.     * @access public
  28.     * 
  29.     * @var string 
  30.     * 
  31.     * @see parse()
  32.     * 
  33.     */
  34.     
  35.     var $regex = '/\n((: ).*\n)(?!(: |\n))/Us';
  36.     
  37.     
  38.     /**
  39.     * 
  40.     * Generates a replacement for the matched text.  Token options are:
  41.     * 
  42.     * 'type' =>
  43.     *     'list_start'    : the start of a definition list
  44.     *     'list_end'      : the end of a definition list
  45.     *     'term_start'    : the start of a definition term
  46.     *     'term_end'      : the end of a definition term
  47.     *     'narr_start'    : the start of definition narrative
  48.     *     'narr_end'      : the end of definition narrative
  49.     *     'unknown'       : unknown type of definition portion
  50.     *
  51.     * @access public
  52.     *
  53.     * @param array &$matches The array of matches from parse().
  54.     *
  55.     * @return A series of text and delimited tokens marking the different
  56.     *  list text and list elements.
  57.     *
  58.     */
  59.     
  60.     function process(&$matches)
  61.     {
  62.         // the replacement text we will return to parse()
  63.         $return = '';
  64.         
  65.         // the list of post-processing matches
  66.         $list = array();
  67.         
  68.         // start the deflist
  69.         $options = array('type' => 'list_start');
  70.         $return .= $this->wiki->addToken($this->rule, $options);
  71.         
  72.         // $matches[1] is the text matched as a list set by parse();
  73.         // create an array called $list that contains a new set of
  74.         // matches for the various definition-list elements.
  75.         preg_match_all(
  76.             '/^(: )(.*)?( : )(.*)?$/Ums',
  77.             $matches[1],
  78.             $list,
  79.             PREG_SET_ORDER
  80.         );
  81.         
  82.         // add each term and narrative
  83.         foreach ($list as $key => $val) {
  84.             $return .= (
  85.                 $this->wiki->addToken($this->rule, array('type' => 'term_start')) .
  86.                 trim($val[2]) .
  87.                 $this->wiki->addToken($this->rule, array('type' => 'term_end')) .
  88.                 $this->wiki->addToken($this->rule, array('type' => 'narr_start')) .
  89.                 trim($val[4]) . 
  90.                 $this->wiki->addToken($this->rule, array('type' => 'narr_end'))
  91.             );
  92.         }
  93.         
  94.         
  95.         // end the deflist
  96.         $options = array('type' => 'list_end');
  97.         $return .= $this->wiki->addToken($this->rule, $options);
  98.         
  99.         // done!
  100.         return "\n" . $return . "\n\n";
  101.     }
  102. }
  103. ?>

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