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