class.Block.php

Go to the documentation of this file.
00001 <?php
00002   /*
00003    This  file is part  of WikiConverter.   WikiConverter is  a program
00004    that  converts   text/wiki  into   other  formats  (like   html  or
00005    xml/docbook).
00006 
00007    Copyright (c) 2005 Dashamir Hoxha, dhoxha@inima.al
00008 
00009    WikiConverter  is free  software;  you can  redistribute it  and/or
00010    modify  it under the  terms of  the GNU  General Public  License as
00011    published by the Free Software  Foundation; either version 2 of the
00012    License, or (at your option) any later version.
00013 
00014    WikiConverter is  distributed in the  hope that it will  be useful,
00015    but  WITHOUT ANY  WARRANTY; without  even the  implied  warranty of
00016    MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
00017    General Public License for more details.
00018 
00019    You should have  received a copy of the  GNU General Public License
00020    along  with  WikiConverter; if  not,  write  to  the Free  Software
00021    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022    USA
00023   */
00024 
00029 class Block extends Tpl
00030 {
00031   var $block_type;
00032   var $block_title;
00033 
00034   function Block($type ='code', $title ='')
00035   {
00036     static $id = 'Block_01';
00037                 
00038     Tpl::Tpl('Block');
00039     $this->id = $id++;
00040     $this->block_type = $type;
00041     $this->block_title = $title;
00042   }
00043 
00044   function to_html($indent, $class)
00045   {
00046     $tag = ($this->block_type=='code' ? 'xmp' : 'pre');
00047     $html = ("\n$indent<$tag $class>"
00048              . Tpl::to_html('', $class)
00049              . "</$tag>\n");
00050     return $html;
00051   }
00052 
00053   function line_to_html($line, $indent)
00054   {
00055     //without changing the whitespace, no trim no indentation
00056     $line = regex_replace($line);
00057     return $line;
00058   }
00059 
00060   function to_xml($indent)
00061   {
00062     $type = $this->block_type;
00063     switch ($type)
00064       {
00065       case 'code':
00066         $tag = 'programlisting';
00067         break;
00068       case 'scr':
00069       case 'screen':
00070         $tag = 'screen';
00071         break;
00072       case 'll':
00073         $tag = 'literallayout';
00074         break;
00075       case 'fig':
00076       case 'figure':
00077         $tag = 'figure';
00078         break;
00079       case 'xmp':
00080       case 'example':
00081         $tag = 'example';
00082         break;
00083       case 'n':
00084       case 'note':
00085         $tag = 'note';
00086         break;
00087       case 'w':
00088       case 'warning':
00089         $tag = 'warning';
00090         break;
00091       case 'c':
00092       case 'caution':
00093         $tag = 'caution';
00094         break;
00095       case 'imp':
00096       case 'important':
00097         $tag = 'important';
00098         break;
00099       case 'tip':
00100         $tag = 'tip';
00101         break;
00102       }
00103 
00104     if ($tag=='programlisting' or $tag=='screen' or $tag=='literallayout')
00105       {
00106         $xml = ("\n$indent<$tag>"
00107                 . Tpl::to_xml()
00108                 . "</$tag>\n");
00109       }
00110     else if ($tag=='figure' or $tag=='example')
00111       {
00112         $title = $this->block_title;
00113         $xml = ("\n$indent<$tag><title>$title</title>"
00114                 . Tpl::to_xml()
00115                 . "$indent</$tag>\n");
00116       }
00117     else //admonitions
00118       {
00119         $title = $this->block_title;
00120         if ($title!='')  $title = '<title>'.$title.'</title>';
00121         $xml = "\n$indent<$tag>$title<para>"
00122           . Tpl::to_xml()
00123           . "</para></$tag>\n";
00124       }
00125 
00126     return $xml;
00127   }
00128 
00129   function line_to_xml($line, $indent)
00130   {
00131     $line = regex_replace($line);
00132     return $line;
00133   }
00134 }
00135 ?>

Generated on Wed Jan 9 08:27:32 2008 for DokBookWiki by  doxygen 1.5.2