OSDN Git Service

avoid PHP pack() bug.
[pukiwiki/pukiwiki.git] / convert_html.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: convert_html.php,v 1.27 2003/03/04 06:38:31 panda Exp $
6 //
7 function convert_html($lines)
8 {
9         global $script,$vars,$digest;
10         static $contents_id = 0;
11         
12         if (!is_array($lines))
13         {
14                 $lines = explode("\n",$lines);
15         }
16         
17         $digest = md5(join('',get_source($vars['page'])));
18         
19         $body = new Body(++$contents_id);
20         $body->parse($lines);
21         $ret = $body->toString();
22         
23         return $ret;
24 }
25
26 class Element
27 {
28         var $parent;
29         
30         function setParent(&$parent)
31         {
32                 $this->parent =& $parent;
33         }
34         function debug($indent = 0)
35         {
36                 return str_repeat(' ',$indent).get_class($this)."({$this->text})\n";
37         }
38 }
39
40 class Inline extends Element
41 { // ¥¤¥ó¥é¥¤¥óÍ×ÁÇ
42         var $text;
43         
44         function Inline($text)
45         {
46                 if (substr($text,0,1) == '~') { // ¹ÔƬ~¡£¥Ñ¥é¥°¥é¥Õ³«»Ï
47                         $parent =& $this->parent;
48                         $this = new Paragraph(' '.substr($text,1));
49                         $this->setParent($parent);
50                 }
51                 else {
52                         $this->text = (substr($text,0,1) == "\n") ? $text : inline2(inline($text));
53                 }
54         }
55         function &add(&$obj)
56         {
57                 return $this->insert($obj);
58         }
59         function &insert(&$obj)
60         {
61                 return $this->parent->add($obj);
62         }
63         function toString()
64         {
65                 return $this->text;
66         }
67         function toPara($class = '')
68         {
69                 $obj = new Paragraph('',$class);
70                 $obj->insert($this);
71                 $this->setParent($obj);
72                 return $obj;
73         }
74 }
75 class Block extends Element
76 { // ¥Ö¥í¥Ã¥¯Í×ÁÇ
77         var $elements; // Í×ÁǤÎÇÛÎó
78         
79         function Block() {
80                 $this->elements = array();
81         }
82         
83         function &add(&$obj) // ¥¨¥ì¥á¥ó¥È¤òÄɲÃ
84         {
85                 if ($this->canContain($obj)) {
86                         return $this->insert($obj);
87                 }
88                 return $this->parent->add($obj);
89         }
90         function &insert(&$obj)
91         {
92                 $obj->setParent($this);
93                 $this->elements[] =& $obj;
94                 if (isset($obj->last) and is_object($obj->last)) {
95                         return $obj->last;
96                 }
97                 return $obj;
98         }
99         function canContain($obj)
100         {
101                 return TRUE;
102         }
103         function toString()
104         {
105                 $ret = '';
106                 if (isset($this->elements) and count($this->elements) > 0) {
107                         foreach ($this->elements as $obj) {
108                                 $ret .= $obj->toString();
109                         }
110                 }
111                 return $ret;
112         }
113         function wrap($string, $tag, $param = '')
114         {
115                 return  ($string == '') ? '' : "\n<$tag$param>$string</$tag>\n";
116         }
117         function debug($indent = 0)
118         {
119                 $ret = parent::debug($indent);
120                 foreach (array_keys($this->elements) as $key) {
121                         if (is_object($this->elements[$key]))
122                                 $ret .= $this->elements[$key]->debug($indent + 2);
123                         else
124                                 $ret .= str_repeat(' ',$indent + 2).$this->elements[$key];
125                 }
126                 return $ret;
127         }
128 }
129 class Paragraph extends Block
130 { // ÃÊÍî
131         var $class;
132         
133         function Paragraph($text,$class='')
134         {
135                 parent::Block();
136                 $this->class = $class;
137                 if ($text == '') {
138                         return;
139                 }
140                 if (substr($text,0,1) == '~') {
141                         $text = ' '.substr($text,1);
142                 }
143                 $this->elements[] =& new Inline($text);
144         }
145         function canContain($obj)
146         {
147                 return is_a($obj,'Inline');
148         }
149         function toString()
150         {
151                 return $this->wrap(parent::toString(), 'p', $this->class);
152         }
153 }
154
155 class Heading extends Block
156 { // *
157         var $level,$id,$msg_top;
158         
159         function Heading(&$root,$text)
160         {
161                 parent::Block();
162                 if (($level = strspn($text,'*')) > 3) {
163                         $level = 3;
164                 }
165                 $text = ltrim(substr($text,$level));
166                 $this->level = ++$level;
167                 list($this->msg_top,$this->id) = $root->getAnchor($text,$level);
168                 $this->last =& $this->insert(new Inline($text));
169         }
170         function canContain(&$obj)
171         {
172                 return FALSE;
173         }
174         function toString()
175         {
176                 return $this->msg_top.
177                         $this->wrap(parent::toString(),'h'.$this->level," id=\"{$this->id}\"");
178         }
179 }
180 class HRule extends Block
181 { // ----
182         function HRule(&$root,$text) {
183                 parent::Block();
184         }
185         function canContain(&$obj)
186         {
187                 return FALSE;
188         }
189         function toString()
190         {
191                 global $hr;
192                 
193                 return $hr;
194         }
195 }
196 class ListContainer extends Block
197 {
198         var $tag,$tag2,$level,$style;
199         var $margin,$left_margin;
200         
201         function ListContainer($tag,$tag2,$level,$text)
202         {
203                 parent::Block();
204                 //¥Þ¡¼¥¸¥ó¤ò¼èÆÀ
205                 $var_margin = "_{$tag}_margin";
206                 $var_left_margin = "_{$tag}_left_margin";
207                 global $$var_margin, $$var_left_margin;
208                 $this->margin = $$var_margin;
209                 $this->left_margin = $$var_left_margin;
210
211                 //½é´ü²½
212                 $this->tag = $tag;
213                 $this->tag2 = $tag2;
214                 $this->level = $level;
215                 
216                 if ($text != '') {
217                         $this->insert(new Inline($text));
218                 }
219         }
220
221         function canContain(&$obj)
222         {
223                 return is_a($obj, 'ListContainer') ? ($this->tag == $obj->tag and $this->level == $obj->level) : TRUE;
224         }
225         function setParent(&$parent)
226         {
227                 global $_list_pad_str;
228
229                 parent::setParent($parent);
230                 $step = $this->level;
231                 if (isset($parent->parent) and is_a($parent->parent,'ListContainer')) {
232                         $step -= $parent->parent->level; 
233                 }
234                 $margin = $this->margin * $step;
235                 if ($step == $this->level) {
236                         $margin += $this->left_margin;
237                 }
238                 $this->style = sprintf($_list_pad_str,$this->level,$margin,$margin);
239         }
240         function &insert(&$obj)
241         {
242                 if (is_a($obj, get_class($this))) {
243                         for ($n = 0; $n < count($obj->elements); $n++) {
244                                 $this->last =& parent::insert($obj->elements[$n]);
245                         }
246                         return $this->last;
247                 }
248                 $obj =& new ListElement($obj, $this->level, $this->tag2); // wrap
249                 $this->last =& $obj;
250                 return parent::insert($obj);
251         }
252         function toString($param='')
253         {
254                 return $this->wrap(parent::toString(),$this->tag,$this->style.$param);
255         }
256 }
257 class ListElement extends Block
258 {
259         function ListElement(&$obj,$level,$head)
260         {
261                 parent::Block();
262                 $this->level = $level;
263                 $this->head = $head;
264                 $this->insert($obj);
265                 $this->last = NULL;
266                 if (isset($obj->last) and is_object($obj->last)) {
267                         $this->last =& $obj->last;
268                 }
269         }
270         function canContain(&$obj)
271         {
272                 return !(is_a($obj, 'ListContainer') and ($obj->level <= $this->level));
273         }
274         function toString()
275         {
276                 return $this->wrap(parent::toString(), $this->head);
277         }
278 }
279 class UList extends ListContainer
280 { // -
281         function UList(&$root,$text)
282         {
283                 if (($level = strspn($text,'-')) > 3) {
284                         $level = 3; // limitation ;(
285                 }
286                 $text = ltrim(substr($text,$level));
287                 parent::ListContainer('ul','li',$level,$text);
288         }
289 }
290 class OList extends ListContainer
291 { // +
292         function OList(&$root,$text)
293         {
294                 if (($level = strspn($text,'+')) > 3) {
295                         $level = 3; // limitation ;(
296                 }
297                 $text = ltrim(substr($text,$level));
298                 parent::ListContainer('ol','li',$level,$text);
299         }
300 }
301 class DList extends ListContainer
302 { // :
303         function DList(&$root,$text)
304         {
305                 if (($level = strspn($text,':')) > 3) {
306                         $level = 3; // limitation ;(
307                 }
308                 $out = explode('|',ltrim(substr($text,$level)),2);
309                 if (count($out) < 2) {
310                         $this = new Inline($text);
311                         return;
312                 }
313                 parent::ListContainer('dl','dd',$level,$out[1]);
314                 if ($out[0] != '') {
315                         array_unshift($this->elements,new Inline("\n<dt>".inline2(inline($out[0]))."</dt>\n"));
316                 }
317         }
318 }
319 class BQuote extends Block
320 { // >
321         var $level;
322         
323         function BQuote(&$root,$text)
324         {
325                 parent::Block();
326                 $head = substr($text,0,1);
327                 if (($level = strspn($text,$head)) > 3) {
328                         $level = 3; // limitation ;(
329                 }
330                 $this->level = $level;
331                 $text = ltrim(substr($text,$level));
332                 if ($head == '<') { //blockquote close
333                         $this->level = 0;
334                         $this->last =& $this->end($root,$level,$text);
335                 }
336                 else {
337                         $this->last =& $this->insert(new Paragraph($text, ' class="quotation"'));
338                 }
339         }
340         function canContain(&$obj)
341         {
342                 if (!is_a($obj, get_class($this))) {
343                         return TRUE;
344                 }
345                 return ($obj->level >= $this->level);
346         }
347         function &insert(&$obj)
348         {
349                 if (is_a($obj, 'BQuote') and $obj->level == $this->level) {
350                         if (is_a($this->last,'Paragraph')
351                                 and array_key_exists(0,$obj->elements[0])
352                                 and is_object($obj->elements[0]->elements[0])) {
353                                 $this->last->insert($obj->elements[0]->elements[0]);
354                         } else {
355                                 $this->last =& $this->insert($obj->elements[0]);
356                         }
357                         return $this->last;
358                 }
359                 $this->last =& $obj;
360                 return parent::insert($obj);
361         }
362         function toString()
363         {
364                 return $this->wrap(parent::toString(),'blockquote');
365         }
366         function &end(&$root,$level,$text)
367         {
368                 $parent =& $root->last;
369                 while (is_object($parent)) {
370                         if (is_a($parent,'BQuote') and $parent->level == $level) {
371                                 return $parent->parent->insert(new Inline($text));
372                         }
373                         $parent =& $parent->parent;
374                 }
375                 return $this->insert(new Inline($text));
376         }
377 }
378 class TableCell extends Block
379 {
380         var $tag = 'td'; // {td|th}
381         var $colspan = 1;
382         var $rowspan = 1;
383         var $style; // is array('width'=>, 'align'=>...);
384         
385         function TableCell($text,$is_template=FALSE) {
386                 parent::Block();
387                 $this->style = array();
388                 
389                 if (preg_match("/^(LEFT|CENTER|RIGHT):(.*)$/",$text,$out)) {
390                         $this->style['align'] = 'text-align:'.strtolower($out[1]).';';
391                         $text = $out[2];
392                 }
393                 if ($is_template) {
394                         if (is_numeric($text)) {
395                                 $this->style['width'] = "width:{$text}px;";
396                         }
397                 }
398                 if ($text == '>') {
399                         $this->colspan = 0;
400                 }
401                 else if ($text == '~') {
402                         $this->rowspan = 0;
403                 }
404                 else if (substr($text,0,1) == '~') {
405                         $this->tag = 'th';
406                         $text = substr($text,1);
407                 }
408                 $this->last =& $this->insert(new Inline($text));
409         }
410         function setStyle(&$style) {
411                 foreach ($style as $key=>$value) {
412                         if (!array_key_exists($key,$this->style)) {
413                                 $this->style[$key] = $value;
414                         }
415                 }
416         }
417         function toString() {
418                 if ($this->rowspan == 0 or $this->colspan == 0) {
419                         return '';
420                 }
421                 $param = " class=\"style_{$this->tag}\"";
422                 if ($this->rowspan > 1) {
423                         $param .= " rowspan=\"{$this->rowspan}\"";
424                 }
425                 if ($this->colspan > 1) {
426                         $param .= " colspan=\"{$this->colspan}\"";
427                         unset($this->style['width']);
428                 }
429                 if (count($this->style)) {
430                         $param .= ' style="'.join(' ',$this->style).'"';
431                 }
432                 return "\n<{$this->tag}$param>".parent::toString()."</{$this->tag}>\n";
433         }
434 }
435 class Table extends Block
436 { // |
437         var $type,$types;
438         var $col; // number of column
439         
440         function Table(&$root,$text)
441         {
442                 if (!preg_match("/^\|(.+)\|([hHfFcC]?)$/",$text,$out)) {
443                         $this = new Inline($text);
444                         return;
445                 }
446                 parent::Block();
447                 $cells = explode('|',$out[1]);
448                 $this->col = count($cells);
449                 $this->type = strtolower($out[2]);
450                 $this->types = array($this->type);
451                 $is_template = ($this->type == 'c');
452                 $row = array();
453                 foreach ($cells as $cell) {
454                         $row[] = new TableCell($cell,$is_template);
455                 }
456                 $this->elements[] = $row;
457                 $this->last =& $this;
458         }
459         function canContain(&$obj)
460         {
461                 return is_a($obj, 'Table') and ($obj->col == $this->col);
462         }
463         function &insert(&$obj)
464         {
465                 $this->elements[] = $obj->elements[0];
466                 $this->types[] = $obj->type;
467                 return $this;
468         }
469         function toString()
470         {
471                 // rowspan¤òÀßÄê(²¼¤«¤é¾å¤Ø)
472                 for ($ncol = 0; $ncol < $this->col; $ncol++) {
473                         $rowspan = 1;
474                         foreach (array_reverse(array_keys($this->elements)) as $nrow) {
475                                 $row =& $this->elements[$nrow];
476                                 if ($row[$ncol]->rowspan == 0) {
477                                         $rowspan++;
478                                 }
479                                 else {
480                                         $row[$ncol]->rowspan = $rowspan;
481                                         while (--$rowspan) { // ¹Ô¼ïÊ̤ò·Ñ¾µ¤¹¤ë
482                                                 $this->types[$nrow + $rowspan] = $this->types[$nrow];
483                                         }
484                                         $rowspan = 1;
485                                 }
486                         }
487                 }
488                 // colspan,style¤òÀßÄê
489                 $stylerow = NULL;
490                 foreach (array_keys($this->elements) as $nrow) {
491                         $row =& $this->elements[$nrow];
492                         if ($this->types[$nrow] == 'c') {
493                                 $stylerow =& $row;
494                         }
495                         $colspan = 1;
496                         foreach (array_keys($row) as $ncol) {
497                                 if ($row[$ncol]->colspan == 0) {
498                                         $colspan++;
499                                 }
500                                 else {
501                                         $row[$ncol]->colspan = $colspan;
502                                         if ($stylerow !== NULL) {
503                                                 $row[$ncol]->setStyle($stylerow[$ncol]->style);
504                                                 while (--$colspan) { // Îó¥¹¥¿¥¤¥ë¤ò·Ñ¾µ¤¹¤ë
505                                                         $row[$ncol - $colspan]->setStyle($stylerow[$ncol]->style);
506                                                 }
507                                         }
508                                         $colspan = 1;
509                                 }
510                         }
511                 }
512                 // ¥Æ¥­¥¹¥È²½
513                 $string = '';
514                 $parts = array('h'=>'thead',''=>'tbody','f'=>'tfoot');
515                 foreach ($parts as $type=>$part) {
516                         $part_string = '';
517                         foreach (array_keys($this->elements) as $nrow) {
518                                 if ($this->types[$nrow] != $type) {
519                                         continue;
520                                 }
521                                 $row =& $this->elements[$nrow];
522                                 $row_string = '';
523                                 foreach (array_keys($row) as $ncol) {
524                                         $row_string .= $row[$ncol]->toString();
525                                 }
526                                 $part_string .= $this->wrap($row_string,'tr');
527                         }
528                         $string .= $this->wrap($part_string,$part);
529                 }
530                 return <<<EOD
531 <div class="ie5">
532  <table class="style_table" cellspacing="1" border="0">
533   $string
534  </table>
535 </div>
536 EOD;
537         }
538 }
539 class YTable extends Block
540 { // ,
541         var $col;
542         
543         function YTable(&$root,$text)
544         {
545                 parent::Block();
546                 if (!preg_match_all('/("[^"]*(?:""[^"]*)*"|[^,]*),/',"$text,",$out)) {
547                         $this = new Inline($text);
548                         return;
549                 }
550                 array_shift($out[1]);
551                 $_value = array();
552                 foreach ($out[1] as $val) {
553                         $_value[] = preg_match('/^"(.*)"$/',$val,$matches) ? str_replace('""','"',$matches[1]) : $val;
554                 }
555                 $align = array();
556                 $value = array();
557                 foreach($_value as $val) {
558                         if (preg_match('/^(\s+)?(.+?)(\s+)?$/',$val,$matches)) {
559                                 $align[] =($matches[1] != '') ?
560                                         ((array_key_exists(3,$matches) and $matches[3] != '') ? ' style="text-align:center"' : ' style="text-align:right"') : '';
561                                 $value[] = $matches[2];
562                         }
563                         else {
564                                 $align[] = '';
565                                 $value[] = $val;
566                         }
567                 }
568                 $this->col = count($value);
569                 $colspan = array();
570                 foreach ($value as $val) {
571                         $colspan[] = ($val == '==') ? 0 : 1;
572                 }
573                 $str = '';
574                 for ($i = 0; $i < count($value); $i++) {
575                         if ($colspan[$i]) {
576                                 while ($i + $colspan[$i] < count($value) and $value[$i + $colspan[$i]] == '==') {
577                                         $colspan[$i]++;
578                                 }
579                                 $colspan[$i] = ($colspan[$i] > 1) ? " colspan=\"{$colspan[$i]}\"" : '';
580                                 $str .= "<td class=\"style_td\"{$align[$i]}{$colspan[$i]}>".inline2(inline($value[$i])).'</td>';
581                         }
582                 }
583                 $this->elements[] = $str;
584         }
585         function canContain(&$obj)
586         {
587                 return is_a($obj, 'YTable') and ($obj->col == $this->col);
588         }
589         function &insert(&$obj)
590         {
591                 $this->elements[] = $obj->elements[0];
592                 return $this;
593         }
594         function toString()
595         {
596                 $rows = '';
597                 foreach ($this->elements as $str) {
598                         $rows .= "\n<tr class=\"style_tr\">$str</tr>\n";
599                 }
600                 return <<<EOD
601
602 <div class="ie5">
603  <table class="style_table" cellspacing="1" border="0">
604   $rows
605  </table>
606 </div>
607
608 EOD;
609         }
610 }
611 class Pre extends Block
612 { // ' '
613         
614         function Pre(&$root,$text)
615         {
616                 parent::Block();
617                 $this->elements[] = htmlspecialchars($text,ENT_NOQUOTES);
618         }
619         function canContain(&$obj)
620         {
621                 return is_a($obj, 'Pre');
622         }
623         function &insert(&$obj)
624         {
625                 $this->elements[] = $obj->elements[0];
626                 return $this;
627         }
628         function toString()
629         {
630                 return $this->wrap(join("\n",$this->elements),'pre');
631         }
632 }
633 class Div extends Block
634 { // #
635         var $name,$param;
636         
637         function Div(&$root,$text)
638         {
639                 if (!preg_match("/^\#([^\(]+)(?:\((.*)\))?/",$text,$out) or !exist_plugin_convert($out[1])) {
640                         $this = new Paragraph($text);
641                         return;
642                 }
643                 parent::Block();
644                 $this->name = $out[1];
645                 $this->param = array_key_exists(2,$out) ? $out[2] : '';
646         }
647         function canContain(&$obj)
648         {
649                 return FALSE;
650         }
651         function toString()
652         {
653                 return do_plugin_convert($this->name,$this->param);
654         }
655 }
656 class Align extends Block
657 { // LEFT:/CENTER:/RIGHT:
658         var $align;
659         
660         function Align($align)
661         {
662                 $this->align = $align;
663         }
664         function canContain(&$obj)
665         {
666                 return is_a($obj,'Inline');
667         }
668         function toString()
669         {
670                 return $this->wrap(parent::toString(),'div',' style="text-align:'.$this->align.'"');
671         }
672 }
673 class Body extends Block
674 { // Body
675         var $id;
676         var $count = 0;
677         var $contents;
678         var $contents_last;
679         var $classes = array('HRule','Heading','Pre','UList','OList','DList','Table','YTable','BQuote','BQuoteEnd','Div');
680
681         function Body($id)
682         {
683                 $this->id = $id;
684                 $this->contents = new Block();
685                 $this->contents_last =& $this->contents;
686                 parent::Block();
687         }
688         function parse(&$lines)
689         {
690                 $this->last =& $this;
691                 
692                 foreach ($lines as $line)
693                 {
694                         if (substr($line,0,2) == '//') //¥³¥á¥ó¥È¤Ï½èÍý¤·¤Ê¤¤
695                         {
696                                 continue;
697                         }
698                         
699                         $align = '';
700                         if (preg_match('/^(LEFT|CENTER|RIGHT):(.*)$/',$line,$matches))
701                         {
702                                 $this->last =& $this->last->add(new Align(strtolower($matches[1]))); // <div style="text-align:...">
703                                 if ($matches[2] == '')
704                                 {
705                                         continue;
706                                 }
707                                 $line = $matches[2];
708                         }
709                         
710                         $line = preg_replace("/[\r\n]*$/",'',$line);
711                         
712                         // ¹ÔƬʸ»ú
713                         $head = substr($line,0,1);
714                         
715                         if ($line == '') { // ¶õ¹Ô
716                                 $this->last =& $this;
717                         }
718                         else if (substr($line,0,4) == '----') { // HRule
719                                 $this->last =& $this->insert(new HRule($this,$line));
720                         }
721                         else if ($head == '*') { // Heading
722                                 $this->last =& $this->insert(new Heading($this,$line));
723                         }
724                         else if ($head == ' ' or $head == "\t") { // Pre
725                                 $this->last =& $this->last->add(new Pre($this,$line));
726                         }
727                         else {
728                                 if (substr($line,-1) == '~') {
729                                         $line = substr($line,0,-1)."\r";
730                                 }
731                                 if      ($head == '-') { // UList
732                                         $this->last =& $this->last->add(new UList($this,$line)); // inline
733                                 }
734                                 else if ($head == '+') { // OList
735                                         $this->last =& $this->last->add(new OList($this,$line)); // inline
736                                 }
737                                 else if ($head == ':') { // DList
738                                         $this->last =& $this->last->add(new DList($this,$line)); // inline
739                                 }
740                                 else if ($head == '|') { // Table
741                                         $this->last =& $this->last->add(new Table($this,$line));
742                                 }
743                                 else if ($head == ',') { // Table(YukiWiki¸ß´¹)
744                                         $this->last =& $this->last->add(new YTable($this,$line));
745                                 }
746                                 else if ($head == '>' or $head == '<') { // BrockQuote
747                                         $this->last =& $this->last->add(new BQuote($this,$line));
748                                 }
749                                 else if ($head == '#') { // Div
750                                         $this->last =& $this->last->add(new Div($this,$line));
751                                 }
752                                 else { // Ä̾ïʸ»úÎó
753                                         $this->last =& $this->last->add(new Inline($line));
754                                 }
755                         }
756                 }
757         }
758         function getAnchor($text,$level)
759         {
760                 global $top;
761                 
762                 $id = "content_{$this->id}_{$this->count}";
763                 $this->count++;
764                 $this->contents_last =& $this->contents_last->add(new Contents_UList($text,$this->id,$level,$id));
765                 return array($this->count > 1 ? $top : '',$id);
766         }
767         function getContents()
768         {
769                 $contents  = "<a id=\"contents_{$this->id}\"></a>";
770                 $contents .= $this->contents->toString();
771                 return $contents;
772         }
773         function &insert(&$obj)
774         {
775                 if (is_a($obj,'Inline')) {
776                         $obj =& $obj->toPara();
777                 }
778                 return parent::insert($obj);
779         }
780         function toString()
781         {
782                 global $vars;
783                 
784                 $text = parent::toString();
785                 
786                 // #contents
787                 $text = preg_replace('/<p[^>]*>#contents<\/p>/',$this->getContents(),$text);
788                 
789                 // ´ØÏ¢¤¹¤ë¥Ú¡¼¥¸
790                 // <p>¤Î¤È¤­¤Ï¹ÔƬ¤«¤é¡¢<del>¤Î¤È¤­¤Ï¾¤ÎÍ×ÁǤλÒÍ×ÁǤȤ·¤Æ¸ºß
791                 $text = preg_replace('/<(p|del)>#related<\/\1>/e','make_related($vars[\'page\'],\'$1\')',$text);
792                 return $text;
793         }
794 }
795 class Contents_UList extends ListContainer
796 {
797         function Contents_UList($text,$id,$level,$id)
798         {
799                 // ¥Æ¥­¥¹¥È¤Î¥ê¥Õ¥©¡¼¥à
800                 // ¹ÔƬ\n¤ÇÀ°·ÁºÑ¤ß¤òɽ¤¹ ... X(
801                 $text = "\n<a href=\"#$id\">".strip_htmltag(inline2(inline($text,TRUE)))."</a>\n";
802                 parent::ListContainer('ul', 'li', --$level, $text);
803         }
804         function setParent(&$parent)
805         {
806                 global $_list_pad_str;
807
808                 parent::setParent($parent);
809                 $step = $this->level;
810                 $margin = $this->left_margin;
811                 if (isset($parent->parent) and is_a($parent->parent,'ListContainer'))
812                 {
813                         $step -= $parent->parent->level;
814                         $margin = 0;
815                 }
816                 $margin += $this->margin * ($step == $this->level ? 1 : $step);
817                 $this->style = sprintf($_list_pad_str,$this->level,$margin,$margin);
818         }
819 }
820 ?>