0f316d03bbfc6c0b3fd56cd972f10cbe6473973d
5 * Looks through parsed text and builds a table of contents.
11 * @author Paul M. Jones <pmjones@php.net>
15 * @version $Id: Toc.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $
21 * Looks through parsed text and builds a table of contents.
23 * This class implements a Text_Wiki_Parse to find all heading tokens and
24 * build a table of contents. The [[toc]] tag gets replaced with a list
25 * of all the level-2 through level-6 headings.
31 * @author Paul M. Jones <pmjones@php.net>
36 class Text_Wiki_Parse_Toc
extends Text_Wiki_Parse
{
41 * The regular expression used to parse the source text and find
42 * matches conforming to this rule. Used by the parse() method.
52 var $regex = "/\n\[\[toc( .*)?\]\]\n/m";
57 * Generates a replacement for the matched text.
61 * 'type' => ['list_start'|'list_end'|'item_start'|'item_end'|'target']
63 * 'level' => The heading level (1-6).
65 * 'count' => Which entry number this is in the list.
69 * @param array &$matches The array of matches from parse().
71 * @return string A token indicating the TOC collection point.
75 function process(&$matches)
79 if (isset($matches[1])) {
80 $attr = $this->getAttrs(trim($matches[1]));
85 $output = $this->wiki
->addToken(
88 'type' => 'list_start',
94 foreach ($this->wiki
->getTokens('Heading') as $key => $val) {
96 if ($val[1]['type'] != 'start') {
101 'type' => 'item_start',
102 'id' => $val[1]['id'],
103 'level' => $val[1]['level'],
107 $output .= $this->wiki
->addToken($this->rule
, $options);
109 $output .= $val[1]['text'];
111 $output .= $this->wiki
->addToken(
114 'type' => 'item_end',
115 'level' => $val[1]['level']
120 $output .= $this->wiki
->addToken(
122 'type' => 'list_end',