1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
/**
* List rule end renderer for Xhtml
*
* PHP versions 4 and 5
*
* @category Text
* @package Text_Wiki
* @author Paul M. Jones <pmjones@php.net>
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version CVS: $Id: List.php,v 1.9 2005/11/06 10:38:22 toggg Exp $
* @link http://pear.php.net/package/Text_Wiki
*/
/**
* This class renders bullet and ordered lists in XHTML.
*
* @category Text
* @package Text_Wiki
* @author Paul M. Jones <pmjones@php.net>
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: @package_version@
* @link http://pear.php.net/package/Text_Wiki
*/
class Text_Wiki_Render_Xhtml_List extends Text_Wiki_Render {
var $conf = array(
'css_ol' => null,
'css_ol_li' => null,
'css_ul' => null,
'css_ul_li' => null
);
/**
*
* Renders a token into text matching the requested format.
*
* This rendering method is syntactically and semantically compliant
* with XHTML 1.1 in that sub-lists are part of the previous list item.
*
* @access public
*
* @param array $options The "options" portion of the token (second
* element).
*
* @return string The text rendered from the token options.
*
*/
function token($options)
{
// make nice variables (type, level, count)
extract($options);
// set up indenting so that the results look nice; we do this
// in two steps to avoid str_pad mathematics. ;-)
$pad = str_pad('', $level, "\t");
$pad = str_replace("\t", ' ', $pad);
switch ($type) {
case 'bullet_list_start':
// build the base HTML
$css = $this->formatConf(' class="%s"', 'css_ul');
$html = "<ul$css>";
/*
// if this is the opening block for the list,
// put an extra newline in front of it so the
// output looks nice.
if ($level == 0) {
$html = "\n$html";
}
*/
// done!
return $html;
break;
case 'bullet_list_end':
// build the base HTML
$html = "</li>\n$pad</ul>";
// if this is the closing block for the list,
// put extra newlines after it so the output
// looks nice.
if ($level == 0) {
$html .= "\n\n";
}
// done!
return $html;
break;
case 'number_list_start':
if (isset($format)) {
$format = ' type="' . $format . '"';
} else {
$format = '';
}
// build the base HTML
$css = $this->formatConf(' class="%s"', 'css_ol');
$html = "<ol{$format}{$css}>";
/*
// if this is the opening block for the list,
// put an extra newline in front of it so the
// output looks nice.
if ($level == 0) {
$html = "\n$html";
}
*/
// done!
return $html;
break;
case 'number_list_end':
// build the base HTML
$html = "</li>\n$pad</ol>";
// if this is the closing block for the list,
// put extra newlines after it so the output
// looks nice.
if ($level == 0) {
$html .= "\n\n";
}
// done!
return $html;
break;
case 'bullet_item_start':
case 'number_item_start':
// pick the proper CSS class
if ($type == 'bullet_item_start') {
$css = $this->formatConf(' class="%s"', 'css_ul_li');
} else {
$css = $this->formatConf(' class="%s"', 'css_ol_li');
}
// build the base HTML
$html = "\n$pad<li$css>";
// for the very first item in the list, do nothing.
// but for additional items, be sure to close the
// previous item.
if ($count > 0) {
$html = "</li>$html";
}
// done!
return $html;
break;
case 'bullet_item_end':
case 'number_item_end':
default:
// ignore item endings and all other types.
// item endings are taken care of by the other types
// depending on their place in the list.
return '';
break;
}
}
}
?>