changed git call from https to git readonly
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / DescHTML.inc
1 <?php\r
2 /**\r
3  * All abstract representations of html tags in DocBlocks are handled by the\r
4  * classes in this file\r
5  *\r
6  * Before version 1.2, phpDocumentor simply passed html to converters, without\r
7  * much thought, except the {@link adv_htmlentities()} function was provided\r
8  * along with a list of allowed html.  That list is no longer used, in favor\r
9  * of these classes.\r
10  *\r
11  * The PDF Converter output looked wretched in version 1.1.0 because line breaks\r
12  * in DocBlocks were honored.  This meant that output often had just a few words\r
13  * on every other line!  To fix this problem, DocBlock descriptions are now\r
14  * parsed using the {@link ParserDescParser}, and split into paragraphs.  In\r
15  * addition, html in DocBlocks are parsed into these objects to allow for easy\r
16  * conversion in destination converters.  This design also allows different\r
17  * conversion for different templates within a converter, which separates\r
18  * design from logic almost 100%\r
19  *\r
20  * phpDocumentor :: automatic documentation generator\r
21  * \r
22  * PHP versions 4 and 5\r
23  *\r
24  * Copyright (c) 2002-2007 Gregory Beaver\r
25  * \r
26  * LICENSE:\r
27  * \r
28  * This library is free software; you can redistribute it\r
29  * and/or modify it under the terms of the GNU Lesser General\r
30  * Public License as published by the Free Software Foundation;\r
31  * either version 2.1 of the License, or (at your option) any\r
32  * later version.\r
33  * \r
34  * This library is distributed in the hope that it will be useful,\r
35  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
36  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
37  * Lesser General Public License for more details.\r
38  * \r
39  * You should have received a copy of the GNU Lesser General Public\r
40  * License along with this library; if not, write to the Free Software\r
41  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
42  * \r
43  * @category   ToolsAndUtilities\r
44  * @package    phpDocumentor\r
45  * @subpackage DescHTML\r
46  * @author     Greg Beaver <cellog@php.net>\r
47  * @copyright  2002-2007 Gregory Beaver\r
48  * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL\r
49  * @version    CVS: $Id: DescHTML.inc,v 1.5 2007/11/17 03:07:00 ashnazg Exp $\r
50  * @filesource\r
51  * @link       http://www.phpdoc.org\r
52  * @link       http://pear.php.net/PhpDocumentor\r
53  * @see        parserDocBlock, parserInclude, parserPage, parserClass\r
54  * @see        parserDefine, parserFunction, parserMethod, parserVar\r
55  * @since      1.2\r
56  * @todo       CS cleanup - change package to PhpDocumentor\r
57  */\r
58 /**\r
59  * Used for <<code>> in a description\r
60  *\r
61  * @category   ToolsAndUtilities\r
62  * @package    phpDocumentor\r
63  * @subpackage DescHTML\r
64  * @author     Greg Beaver <cellog@php.net>\r
65  * @copyright  2002-2007 Gregory Beaver\r
66  * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL\r
67  * @version    Release: 1.4.1\r
68  * @link       http://www.phpdoc.org\r
69  * @link       http://pear.php.net/PhpDocumentor\r
70  * @since      1.2\r
71  * @todo       CS cleanup - change package to PhpDocumentor\r
72  * @todo       CS cleanup - rename class to ParserCode\r
73  */\r
74 class parserCode extends parserStringWithInlineTags\r
75 {\r
76     /**\r
77      * performs the conversion of code tags\r
78      *\r
79      * @param Converter &$c the converter object\r
80      *\r
81      * @return string the converted code block\r
82      * @uses Converter::ProgramExample()\r
83      * @todo CS cleanup - rename method to convert()\r
84      */\r
85     function Convert(&$c)\r
86     {\r
87         if (!isset($this->value[0])) {\r
88             return '';\r
89         }\r
90         if (is_string($this->value[0]) && $this->value[0]{0} == "\n") {\r
91             $this->value[0] = substr($this->value[0], 1);\r
92         }\r
93         $linktags = array();\r
94         foreach ($this->value as $val) {\r
95             if (phpDocumentor_get_class($val) == 'parserlinkinlinetag'\r
96                 || phpDocumentor_get_class($val) == 'parsertutorialinlinetag'\r
97             ) {\r
98                 $linktags[] = array(\r
99                     $c->postProcess($val->Convert($c, false, false)), $val);\r
100             }\r
101         }\r
102         $a = $c->ProgramExample(rtrim(ltrim(parent::Convert($c,\r
103             false, false), "\n\r")));\r
104         foreach ($linktags as $tag) {\r
105             $a = str_replace($tag[0], $tag[1]->Convert($c, false, false), $a);\r
106         }\r
107         return $a;\r
108     }\r
109 }\r
110 \r
111 /**\r
112  * Used for <<pre>> in a description\r
113  *\r
114  * @category   ToolsAndUtilities\r
115  * @package    phpDocumentor\r
116  * @subpackage DescHTML\r
117  * @author     Greg Beaver <cellog@php.net>\r
118  * @copyright  2002-2007 Gregory Beaver\r
119  * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL\r
120  * @version    Release: 1.4.1\r
121  * @link       http://www.phpdoc.org\r
122  * @link       http://pear.php.net/PhpDocumentor\r
123  * @since      1.2\r
124  * @todo       CS cleanup - change package to PhpDocumentor\r
125  * @todo       CS cleanup - rename class to ParserPre\r
126  */\r
127 class parserPre extends parserStringWithInlineTags\r
128 {\r
129     /**\r
130      * performs the conversion of code tags\r
131      *\r
132      * @param Converter &$c the converter object\r
133      *\r
134      * @return string the converted pre block\r
135      * @uses Converter::PreserveWhiteSpace()\r
136      * @todo CS cleanup - rename method to convert()\r
137      */\r
138     function Convert(&$c)\r
139     {\r
140         return $c->PreserveWhiteSpace(rtrim(ltrim(parent::Convert($c,\r
141             false, false), "\n\r")));\r
142     }\r
143 }\r
144 \r
145 /**\r
146  * Used for <<b>> in a description\r
147  *\r
148  * @category   ToolsAndUtilities\r
149  * @package    phpDocumentor\r
150  * @subpackage DescHTML\r
151  * @author     Greg Beaver <cellog@php.net>\r
152  * @copyright  2002-2007 Gregory Beaver\r
153  * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL\r
154  * @version    Release: 1.4.1\r
155  * @link       http://www.phpdoc.org\r
156  * @link       http://pear.php.net/PhpDocumentor\r
157  * @since      1.2\r
158  * @todo       CS cleanup - change package to PhpDocumentor\r
159  * @todo       CS cleanup - rename class to ParserB\r
160  */\r
161 class parserB extends parserStringWithInlineTags\r
162 {\r
163     /**\r
164      * performs the conversion of bold tags\r
165      *\r
166      * @param Converter &$c the converter object\r
167      *\r
168      * @return string the converted pre block\r
169      * @uses Converter::Bolden()\r
170      * @todo CS cleanup - rename method to convert()\r
171      */\r
172     function Convert(&$c)\r
173     {\r
174         return $c->Bolden(parent::Convert($c));\r
175     }\r
176 }\r
177 \r
178 /**\r
179  * Used for <<i>> in a description\r
180  *\r
181  * @category   ToolsAndUtilities\r
182  * @package    phpDocumentor\r
183  * @subpackage DescHTML\r
184  * @author     Greg Beaver <cellog@php.net>\r
185  * @copyright  2002-2007 Gregory Beaver\r
186  * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL\r
187  * @version    Release: 1.4.1\r
188  * @link       http://www.phpdoc.org\r
189  * @link       http://pear.php.net/PhpDocumentor\r
190  * @since      1.2\r
191  * @todo       CS cleanup - change package to PhpDocumentor\r
192  * @todo       CS cleanup - rename class to ParserI\r
193  */\r
194 class parserI extends parserStringWithInlineTags\r
195 {\r
196     /**\r
197      * performs the conversion of italic tags\r
198      *\r
199      * @param Converter &$c the converter object\r
200      *\r
201      * @return string the converted pre block\r
202      * @uses Converter::Italicize()\r
203      * @todo CS cleanup - rename method to convert()\r
204      */\r
205     function Convert(&$c)\r
206     {\r
207         return $c->Italicize(parent::Convert($c));\r
208     }\r
209 }\r
210 \r
211 /**\r
212  * Used for <<var>> in a description\r
213  *\r
214  * @category   ToolsAndUtilities\r
215  * @package    phpDocumentor\r
216  * @subpackage DescHTML\r
217  * @author     Greg Beaver <cellog@php.net>\r
218  * @copyright  2002-2007 Gregory Beaver\r
219  * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL\r
220  * @version    Release: 1.4.1\r
221  * @link       http://www.phpdoc.org\r
222  * @link       http://pear.php.net/PhpDocumentor\r
223  * @since      1.2\r
224  * @todo       CS cleanup - change package to PhpDocumentor\r
225  * @todo       CS cleanup - rename class to ParserDescVar\r
226  */\r
227 class parserDescVar extends parserStringWithInlineTags\r
228 {\r
229     /**\r
230      * performs the conversion of variable tags\r
231      *\r
232      * @param Converter &$c the converter object\r
233      *\r
234      * @return string the converted pre block\r
235      * @uses Converter::Varize()\r
236      * @todo CS cleanup - rename method to convert()\r
237      */\r
238     function Convert(&$c)\r
239     {\r
240         return $c->Varize(parent::Convert($c));\r
241     }\r
242 }\r
243 \r
244 /**\r
245  * Used for <<samp>> in a description\r
246  *\r
247  * @category   ToolsAndUtilities\r
248  * @package    phpDocumentor\r
249  * @subpackage DescHTML\r
250  * @author     Greg Beaver <cellog@php.net>\r
251  * @copyright  2002-2007 Gregory Beaver\r
252  * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL\r
253  * @version    Release: 1.4.1\r
254  * @link       http://www.phpdoc.org\r
255  * @link       http://pear.php.net/PhpDocumentor\r
256  * @since      1.2\r
257  * @todo       CS cleanup - change package to PhpDocumentor\r
258  * @todo       CS cleanup - rename class to ParserSamp\r
259  */\r
260 class parserSamp extends parserStringWithInlineTags\r
261 {\r
262     /**\r
263      * performs the conversion of sample tags\r
264      *\r
265      * @param Converter &$c the converter object\r
266      *\r
267      * @return string the converted pre block\r
268      * @uses Converter::Sampize()\r
269      * @todo CS cleanup - rename method to convert()\r
270      */\r
271     function Convert(&$c)\r
272     {\r
273         return $c->Sampize(parent::Convert($c));\r
274     }\r
275 }\r
276 \r
277 /**\r
278  * Used for <<kbd>> in a description\r
279  *\r
280  * @category   ToolsAndUtilities\r
281  * @package    phpDocumentor\r
282  * @subpackage DescHTML\r
283  * @author     Greg Beaver <cellog@php.net>\r
284  * @copyright  2002-2007 Gregory Beaver\r
285  * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL\r
286  * @version    Release: 1.4.1\r
287  * @link       http://www.phpdoc.org\r
288  * @link       http://pear.php.net/PhpDocumentor\r
289  * @since      1.2\r
290  * @todo       CS cleanup - change package to PhpDocumentor\r
291  * @todo       CS cleanup - rename class to ParserKbd\r
292  */\r
293 class parserKbd extends parserStringWithInlineTags\r
294 {\r
295     /**\r
296      * performs the conversion of keyboard tags\r
297      *\r
298      * @param Converter &$c the converter object\r
299      *\r
300      * @return string the converted pre block\r
301      * @uses Converter::Kbdize()\r
302      * @todo CS cleanup - rename method to convert()\r
303      */\r
304     function Convert(&$c)\r
305     {\r
306         return $c->Kbdize(parent::Convert($c));\r
307     }\r
308 }\r
309 \r
310 /**\r
311  * Used for <<br>> in a description\r
312  *\r
313  * @category   ToolsAndUtilities\r
314  * @package    phpDocumentor\r
315  * @subpackage DescHTML\r
316  * @author     Greg Beaver <cellog@php.net>\r
317  * @copyright  2002-2007 Gregory Beaver\r
318  * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL\r
319  * @version    Release: 1.4.1\r
320  * @link       http://www.phpdoc.org\r
321  * @link       http://pear.php.net/PhpDocumentor\r
322  * @since      1.2\r
323  * @todo       CS cleanup - change package to PhpDocumentor\r
324  * @todo       CS cleanup - rename class to ParserBr\r
325  */\r
326 class parserBr extends parserStringWithInlineTags\r
327 {\r
328     /**\r
329      * performs the conversion of linebreak tags\r
330      *\r
331      * @param Converter &$c the converter object\r
332      *\r
333      * @return string the converted pre block\r
334      * @uses Converter::Br()\r
335      * @todo CS cleanup - rename method to convert()\r
336      */\r
337     function Convert(&$c)\r
338     {\r
339         return $c->Br($this->getString());\r
340     }\r
341 }\r
342 \r
343 /**\r
344  * Used for lists <<ol>> and <<ul>>\r
345  *\r
346  * @category   ToolsAndUtilities\r
347  * @package    phpDocumentor\r
348  * @subpackage DescHTML\r
349  * @author     Greg Beaver <cellog@php.net>\r
350  * @copyright  2002-2007 Gregory Beaver\r
351  * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL\r
352  * @version    Release: 1.4.1\r
353  * @link       http://www.phpdoc.org\r
354  * @link       http://pear.php.net/PhpDocumentor\r
355  * @since      1.2\r
356  * @todo       CS cleanup - change package to PhpDocumentor\r
357  * @todo       CS cleanup - rename class to ParserList\r
358  */\r
359 class parserList extends parserStringWithInlineTags\r
360 {\r
361     /**\r
362      * @var boolean\r
363      */\r
364     var $numbered;\r
365     /**\r
366      * @var integer\r
367      */\r
368     var $items = 0;\r
369     /**\r
370      * Constructor - create a new list\r
371      *\r
372      * @param integer $numbered a reference number for the new list\r
373      */\r
374     function parserList($numbered)\r
375     {\r
376         $this->numbered = $numbered;\r
377     }\r
378     \r
379     /**\r
380      * add an item to a list\r
381      *\r
382      * @param parserStringWithInlineTags $item the item to add\r
383      *\r
384      * @return void\r
385      */\r
386     function addItem($item)\r
387     {\r
388         $this->value[$this->items++] = $item;\r
389     }\r
390     \r
391     /**\r
392      * add a list\r
393      *\r
394      * @param parserList $list the list to add\r
395      *\r
396      * @return void\r
397      */\r
398     function addList($list)\r
399     {\r
400         $this->value[$this->items++] = $list;\r
401     }\r
402     \r
403     /**\r
404      * performs the conversion of list tags\r
405      *\r
406      * @param Converter &$c the converter object\r
407      *\r
408      * @return string the converted pre block\r
409      * @uses Converter::ListItem() enclose each item of the list\r
410      * @uses Converter::EncloseList() enclose the list\r
411      * @todo CS cleanup - rename method to convert()\r
412      */\r
413     function Convert(&$c)\r
414     {\r
415         $list = '';\r
416         foreach ($this->value as $item) {\r
417             $list .= $c->ListItem(trim($item->Convert($c)));\r
418         }\r
419         return $c->EncloseList($list, $this->numbered);\r
420     }\r
421 }\r
422 \r
423 ?>\r