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

Source for file Heading.php

Documentation is available at Heading.php

  1. <?php
  2. // $Id: Heading.php,v 1.4 2004/09/25 19:05:13 pmjones Exp $
  3.  
  4.  
  5. /**
  6. * This class implements a Text_Wiki_Parse to find source text marked to
  7. * be a heading element, as defined by text on a line by itself prefixed
  8. * with a number of plus signs (+). The heading text itself is left in
  9. * the source, but is prefixed and suffixed with delimited tokens marking
  10. * the start and end of the heading.
  11. *
  12. @author Paul M. Jones <pmjones@ciaweb.net>
  13. *
  14. @package Text_Wiki
  15. *
  16. */
  17.  
  18.     
  19.     
  20.     /**
  21.     * 
  22.     * The regular expression used to parse the source text and find
  23.     * matches conforming to this rule.  Used by the parse() method.
  24.     * 
  25.     * @access public
  26.     * 
  27.     * @var string 
  28.     * 
  29.     * @see parse()
  30.     * 
  31.     */
  32.     
  33.     var $regex = '/^(\+{1,6}) (.*)/m';
  34.     
  35.     var $conf = array(
  36.         'id_prefix' => 'toc'
  37.     );
  38.     
  39.     /**
  40.     * 
  41.     * Generates a replacement for the matched text.  Token options are:
  42.     * 
  43.     * 'type' => ['start'|'end'] The starting or ending point of the
  44.     * heading text.  The text itself is left in the source.
  45.     * 
  46.     * @access public
  47.     *
  48.     * @param array &$matches The array of matches from parse().
  49.     *
  50.     * @return string A pair of delimited tokens to be used as a
  51.     *  placeholder in the source text surrounding the heading text.
  52.     *
  53.     */
  54.     
  55.     function process(&$matches)
  56.     {
  57.         // keep a running count for header IDs.  we use this later
  58.         // when constructing TOC entries, etc.
  59.         static $id;
  60.         if (isset($id)) {
  61.             $id = 0;
  62.         }
  63.         
  64.         $prefix htmlspecialchars($this->getConf('id_prefix'));
  65.         
  66.         $start $this->wiki->addToken(
  67.             $this->rule
  68.             array(
  69.                 'type' => 'start',
  70.                 'level' => strlen($matches[1]),
  71.                 'text' => $matches[2],
  72.                 'id' => $prefix $id ++
  73.             )
  74.         );
  75.         
  76.         $end $this->wiki->addToken(
  77.             $this->rule
  78.             array(
  79.                 'type' => 'end',
  80.                 'level' => strlen($matches[1])
  81.             )
  82.         );
  83.         
  84.         return $start $matches[2$end "\n";
  85.     }
  86. }
  87. ?>

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