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

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