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

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