5 * Parses for heading text.
11 * @author Paul M. Jones <pmjones@php.net>
15 * @version $Id: Heading.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $
21 * Parses for heading text.
23 * This class implements a Text_Wiki_Parse 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.
33 * @author Paul M. Jones <pmjones@php.net>
37 class Text_Wiki_Parse_Heading
extends Text_Wiki_Parse
{
42 * The regular expression used to parse the source text and find
43 * matches conforming to this rule. Used by the parse() method.
53 var $regex = '/^(\+{1,6}) (.*)/m';
61 * Generates a replacement for the matched text. Token options are:
63 * 'type' => ['start'|'end'] The starting or ending point of the
64 * heading text. The text itself is left in the source.
68 * @param array &$matches The array of matches from parse().
70 * @return string A pair of delimited tokens to be used as a
71 * placeholder in the source text surrounding the heading text.
75 function process(&$matches)
77 // keep a running count for header IDs. we use this later
78 // when constructing TOC entries, etc.
84 $prefix = htmlspecialchars($this->getConf('id_prefix'));
86 $start = $this->wiki
->addToken(
90 'level' => strlen($matches[1]),
91 'text' => $matches[2],
92 'id' => $prefix . $id ++
96 $end = $this->wiki
->addToken(
100 'level' => strlen($matches[1])
104 return $start . $matches[2] . $end . "\n";