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. /* 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: heading.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 to
  24. * be a heading element, as defined by text on a line by itself prefixed
  25. * with a number of plus signs (+). The heading text itself is left in
  26. * the source, but is prefixed and suffixed with delimited tokens marking
  27. * the start and end of the heading.
  28. *
  29. @author Paul M. Jones <pmjones@ciaweb.net>
  30. *
  31. @package Text_Wiki
  32. *
  33. */
  34.  
  35.     
  36.     
  37.     /**
  38.     * 
  39.     * The regular expression used to parse the source text and find
  40.     * matches conforming to this rule.  Used by the parse() method.
  41.     * 
  42.     * @access public
  43.     * 
  44.     * @var string 
  45.     * 
  46.     * @see parse()
  47.     * 
  48.     */
  49.     
  50.     var $regex = '/^(\+{1,6}) (.*)/m';
  51.     
  52.     
  53.     /**
  54.     * 
  55.     * Generates a replacement for the matched text.  Token options are:
  56.     * 
  57.     * 'type' => ['start'|'end'] The starting or ending point of the
  58.     * heading text.  The text itself is left in the source.
  59.     * 
  60.     * @access public
  61.     *
  62.     * @param array &$matches The array of matches from parse().
  63.     *
  64.     * @return string A pair of delimited tokens to be used as a
  65.     *  placeholder in the source text surrounding the heading text.
  66.     *
  67.     */
  68.     
  69.     function process(&$matches)
  70.     {
  71.         $start $this->addToken(
  72.             array(
  73.                 'type' => 'start',
  74.                 'level' => strlen($matches[1]),
  75.                 'text' => $matches[2]
  76.             )
  77.         );
  78.         
  79.         $end $this->addToken(
  80.             array(
  81.                 'type' => 'end',
  82.                 'level' => strlen($matches[1])
  83.             )
  84.         );
  85.         
  86.         return $start $matches[2$end "\n";
  87.     }
  88.     
  89.     
  90.     /**
  91.     * 
  92.     * Renders a token into text matching the requested format.
  93.     * 
  94.     * @access public
  95.     * 
  96.     * @param array $options The "options" portion of the token (second
  97.     *  element).
  98.     * 
  99.     * @return string The text rendered from the token options.
  100.     * 
  101.     */
  102.     
  103.     function renderXhtml($options)
  104.     {
  105.         // get nice variable names (type, level)
  106.         extract($options);
  107.         
  108.         if ($type == 'start'{
  109.             return "<h$level>";
  110.         }
  111.         
  112.         if ($type == 'end'{
  113.             return "</h$level>\n";
  114.         }
  115.     }
  116. }
  117. ?>

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