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. * 
  7. * This class implements a Text_Wiki_Parse to find source text marked to
  8. * be a heading element, as defined by text on a line by itself prefixed
  9. * with a number of plus signs (+). The heading text itself is left in
  10. * the source, but is prefixed and suffixed with delimited tokens marking
  11. * the start and end of the heading.
  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 = '/^(\+{1,6}) (.*)/m';
  35.     
  36.     var $conf = array(
  37.         'id_prefix' => 'toc'
  38.     );
  39.     
  40.     /**
  41.     * 
  42.     * Generates a replacement for the matched text.  Token options are:
  43.     * 
  44.     * 'type' => ['start'|'end'] The starting or ending point of the
  45.     * heading text.  The text itself is left in the source.
  46.     * 
  47.     * @access public
  48.     *
  49.     * @param array &$matches The array of matches from parse().
  50.     *
  51.     * @return string A pair of delimited tokens to be used as a
  52.     *  placeholder in the source text surrounding the heading text.
  53.     *
  54.     */
  55.     
  56.     function process(&$matches)
  57.     {
  58.         // keep a running count for header IDs.  we use this later
  59.         // when constructing TOC entries, etc.
  60.         static $id;
  61.         if (! isset($id)) {
  62.             $id = 0;
  63.         }
  64.         
  65.         $prefix = htmlspecialchars($this->getConf('id_prefix'));
  66.         
  67.         $start = $this->wiki->addToken(
  68.             $this->rule, 
  69.             array(
  70.                 'type' => 'start',
  71.                 'level' => strlen($matches[1]),
  72.                 'text' => $matches[2],
  73.                 'id' => $prefix . $id ++
  74.             )
  75.         );
  76.         
  77.         $end = $this->wiki->addToken(
  78.             $this->rule, 
  79.             array(
  80.                 'type' => 'end',
  81.                 'level' => strlen($matches[1])
  82.             )
  83.         );
  84.         
  85.         return $start . $matches[2] . $end . "\n";
  86.     }
  87. }
  88. ?>

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