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