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

Source for file Toc.php

Documentation is available at Toc.php

  1. <?php
  2. // $Id: Toc.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 all heading tokens and
  7. * build a table of contents.  The [[toc]] tag gets replaced with a list
  8. * of all the level-2 through level-6 headings.
  9. *
  10. @author Paul M. Jones <pmjones@ciaweb.net>
  11. *
  12. @package Text_Wiki
  13. *
  14. */
  15.  
  16.  
  17.     
  18.     
  19.     /**
  20.     * 
  21.     * The regular expression used to parse the source text and find
  22.     * matches conforming to this rule.  Used by the parse() method.
  23.     * 
  24.     * @access public
  25.     * 
  26.     * @var string 
  27.     * 
  28.     * @see parse()
  29.     * 
  30.     */
  31.     
  32.     var $regex = "/\n\[\[toc( .*)?\]\]\n/m";
  33.     
  34.     
  35.     /**
  36.     * 
  37.     * Generates a replacement for the matched text.
  38.     *  
  39.     * Token options are:
  40.     * 
  41.     * 'type' => ['list_start'|'list_end'|'item_start'|'item_end'|'target']
  42.     *
  43.     * 'level' => The heading level (1-6).
  44.     *
  45.     * 'count' => Which entry number this is in the list.
  46.     * 
  47.     * @access public
  48.     *
  49.     * @param array &$matches The array of matches from parse().
  50.     *
  51.     * @return string A token indicating the TOC collection point.
  52.     *
  53.     */
  54.     
  55.     function process(&$matches)
  56.     {
  57.         $count = 0;
  58.         
  59.         if (isset($matches[1])) {
  60.             $attr $this->getAttrs(trim($matches[1]));
  61.         else {
  62.             $attr = array();
  63.         }
  64.         
  65.         $output $this->wiki->addToken(
  66.             $this->rule,
  67.             array(
  68.                 'type' => 'list_start',
  69.                 'level' => 0,
  70.                 'attr' => $attr
  71.             )
  72.         );
  73.         
  74.         foreach ($this->wiki->getTokens('Heading'as $key => $val{
  75.             
  76.             if ($val[1]['type'!= 'start'{
  77.                 continue;
  78.             }
  79.             
  80.             $options = array(
  81.                 'type'  => 'item_start',
  82.                 'id'    => $val[1]['id'],
  83.                 'level' => $val[1]['level'],
  84.                 'count' => $count ++
  85.             );
  86.             
  87.             $output .= $this->wiki->addToken($this->rule$options);
  88.             
  89.             $output .= $val[1]['text'];
  90.             
  91.             $output .= $this->wiki->addToken(
  92.                 $this->rule,
  93.                 array(
  94.                     'type' => 'item_end',
  95.                     'level' => $val[1]['level']
  96.                 )
  97.             );
  98.         }
  99.         
  100.         $output .= $this->wiki->addToken(
  101.             $this->rulearray(
  102.                 'type' => 'list_end',
  103.                 'level' => 0
  104.             )
  105.         );
  106.         
  107.         return $output;
  108.     }
  109. }
  110. ?>

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