Changeset 1411 for trunk/buildscripts/texbuilder/Page2Tex.php
- Timestamp:
- 09/13/2006 06:33:41 PM (2 years ago)
- Files:
-
- 1 modified
-
trunk/buildscripts/texbuilder/Page2Tex.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/buildscripts/texbuilder/Page2Tex.php
r1265 r1411 1 1 <?php 2 2 3 class Page2Tex 3 class Page2Tex 4 4 { 5 5 private $_current_page; … … 17 17 $this->_dir = $dir; 18 18 } 19 19 20 20 function setCurrentPage($current) 21 21 { … … 25 25 function escape_verbatim($matches) 26 26 { 27 return "\begin{verbatim}".str_replace($this->_verb_find, $this->_verb_replace, $matches[1])."\end{verbatim}\n"; 28 } 29 27 return "\begin{small}\begin{verbatim}". 28 str_replace($this->_verb_find, $this->_verb_replace, $matches[1]). 29 "\end{verbatim}\end{small}\n"; 30 } 31 30 32 function escape_verb($matches) 31 33 { 32 34 $text = str_replace($this->_verb_find, $this->_verb_replace, $matches[1]); 33 return '\ verb<'.$text.'<';34 } 35 35 return '\begin{small}\verb<'.$text.'< \end{small}'; 36 } 37 36 38 function include_image($matches) 37 39 { 38 40 39 41 $current_path = $this->_current_page; 40 42 41 43 $image = dirname($current_path).'/'.trim($matches[1]); 42 44 43 45 $file = realpath($image); 44 46 $info = getimagesize($file); … … 52 54 } 53 55 $base = $this->_base; 54 56 55 57 if(isset($im)) 56 58 { … … 65 67 } 66 68 } 67 69 68 70 function include_figure($info, $filename) 69 71 { … … 77 79 '; 78 80 } 79 81 80 82 function anchor($matches) 81 83 { … … 83 85 return '\hypertarget{'.$page.'/'.strtolower($matches[1]).'}{}'; 84 86 } 85 87 86 88 function texttt($matches) 87 89 { 88 90 return '\texttt{'.str_replace(array('#','_'),array('\#','\_'), $matches[1]).'}'; 89 91 } 90 92 91 93 function get_current_path() 92 94 { … … 96 98 return $page; 97 99 } 98 100 99 101 function make_link($matches) 100 102 { … … 121 123 return '\href{'.$matches[1].'}{'.$matches[2].'}'; 122 124 } 123 125 124 126 function parse_html($page,$html) 125 127 { 126 127 128 128 $html = preg_replace('/<\/?com:TContent[^>]*>/', '', $html); 129 129 $html = preg_replace('/<\/?p [^>]*>/', '', $html); 130 130 $html = preg_replace('/<\/?p>/', '', $html); 131 131 132 132 $html = preg_replace('/(\s+|\(+|\[+)"/', '$1``', $html); 133 133 134 134 //escape { and } 135 135 $html = preg_replace('/([^\s]+){([^}]*)}([^\s]+)/', '$1\\\{$2\\\}$3', $html); 136 136 137 137 $html = preg_replace_callback('/<img\s+src="?<%~([^"]*)%>"?[^>]*\/>/', array($this, 'include_image'), $html); 138 138 139 139 //escape % 140 140 $html = str_replace('%', '\%', $html); 141 141 142 142 //codes 143 143 $html = str_replace('$', '\$', $html); 144 144 145 145 $html = preg_replace_callback('/<com:TTextHighlighter[^>]*>((.|\n)*?)<\/com:TTextHighlighter>/', array($this,'escape_verbatim'), $html); 146 146 // $html = preg_replace('/<\/com:TTextHighlighter>/', '`2`', $html); … … 148 148 $html = preg_replace_callback('/(<div class="source">)((.|\n)*?)(<\/div>)/', array($this,'escape_verbatim'), $html); 149 149 $html = preg_replace_callback('/(<pre>)([^<]*)(<\/pre>)/', array($this,'escape_verbatim'), $html); 150 150 151 151 //<code> 152 152 $html = preg_replace_callback('/<code>([^<]*)<\/code>/', array($this,'escape_verb'), $html); 153 153 154 154 //runbar 155 155 $html = preg_replace('/<com:RunBar\s+PagePath="([^"]*)"\s+\/>/', 156 156 '\href{http://www.pradosoft.com/demos/quickstart/index.php?page=$1}{$1 Demo}', $html); 157 157 158 158 //DocLink 159 159 $html = preg_replace('/<com:DocLink\s+ClassPath="([^"]*)[.]([^.]*)"\s+\/>/', 160 160 '\href{http://www.pradosoft.com/docs/manual/$1/$2.html}{$1.$2 API Reference}', $html); 161 161 162 162 //text modifiers 163 $html = preg_replace('/< b[^>]*>([^<]*)<\/b>/', '\textbf{$1}', $html);163 $html = preg_replace('/<(b|strong)[^>]*>([^<]*)<\/(b|strong)>/', '\textbf{$2}', $html); 164 164 $html = preg_replace('/<i[^>]*>([^<]*)<\/i>/', '\emph{$1}', $html); 165 165 $html = preg_replace_callback('/<tt>([^<]*)<\/tt>/', array($this,'texttt'), $html); 166 166 167 167 //links 168 168 $html = preg_replace_callback('/<a[^>]+href="([^"]*)"[^>]*>([^<]*)<\/a>/', … … 170 170 //anchor 171 171 $html = preg_replace_callback('/<a[^>]+name="([^"]*)"[^>]*><\/a>/', array($this,'anchor'), $html); 172 172 173 173 //description <dl> 174 174 $html = preg_replace('/<dt>([^<]*)<\/dt>/', '\item[$1]', $html); … … 176 176 $html = preg_replace('/<dl>/', '\begin{description}', $html); 177 177 $html = preg_replace('/<\/dl>/', '\end{description}', $html); 178 178 179 179 //item lists 180 180 $html = preg_replace('/<ul[^>]*>/', '\begin{itemize}', $html); … … 184 184 $html = preg_replace('/<li[^>]*>/', '\item ', $html); 185 185 $html = preg_replace('/<\/li>/', '', $html); 186 186 187 187 //headings 188 188 $html = preg_replace('/<h1(\s+id="[^"]+")?>([^<]+)<\/h1>/', '\section{$2}', $html); 189 189 $html = preg_replace('/<h2(\s+id="[^"]+")?>([^<]+)<\/h2>/', '\subsection{$2}', $html); 190 190 $html = preg_replace('/<h3(\s+id="[^"]+")?>([^<]+)<\/h3>/', '\subsubsection{$2}', $html); 191 191 192 192 //div box 193 193 $html = preg_replace_callback('/<div class="[tipnofe]*?">((.|\n)*?)<\/div>/', 194 array($this, 'mbox'), $html); 195 194 array($this, 'mbox'), $html); 195 196 196 //tabular 197 197 $html = preg_replace_callback('/<!--\s*tabular:([^-]*)-->\s*<table[^>]*>((.|\n)*?)<\/table>/', 198 198 array($this, 'tabular'), $html); 199 199 200 $html = preg_replace('/<!--(.*)-->/', '', $html); 201 202 200 203 $html = html_entity_decode($html); 201 204 202 205 return $html; 203 206 } 204 207 205 208 function tabular($matches) 206 209 { … … 211 214 $options[trim($sub[0])] = trim($sub[1]); 212 215 } 213 216 214 217 $widths = explode(' ',preg_replace('/\(|\)/', '', $options['width'])); 215 218 $this->_tabular_widths = $widths; 216 219 217 220 $this->_tabular_total = count($widths); 218 221 $this->_tabular_col = 0; 219 222 220 223 $begin = "\begin{table}[!hpt]\centering \n \begin{tabular}{".$options['align']."}\\hline"; 221 224 $end = "\end{tabular} \n \end{table}\n"; … … 225 228 $table = preg_replace_callback('/<td>((.|\n)*?)<\/td>/', array($this, 'table_column'), $table); 226 229 $table = preg_replace('/<br \/>/', ' \\\\\\\\', $table); 227 230 228 231 $table = preg_replace('/&\s*\\\\\\\\/', '\\\\\\\\', $table); 229 232 return $begin.$table.$end; 230 233 } 231 234 232 235 function table_column($matches) 233 236 { … … 240 243 $matches[1].'\vspace{3mm}\end{minipage} & '; 241 244 } 242 245 243 246 function mbox($matches) 244 247 { 245 248 return "\n\begin{mybox}\n".$matches[1]."\n\end{mybox}\n"; 246 249 } 247 250 248 251 function get_chapter_label($chapter) 249 252 { 250 253 return '\hypertarget{'.str_replace(' ', '', $chapter).'}{}'; 251 254 } 252 255 253 256 function get_section_label($section) 254 257 { … … 256 259 return '\hypertarget{'.str_replace('/', '.', $section).'}{}'; 257 260 } 258 259 261 262 260 263 function set_header_id($content, $count) 261 264 { … … 266 269 return $content; 267 270 } 268 271 269 272 function h1($matches) 270 273 { 271 274 return "<h1 id=\"".(++self::$header_count)."\">"; 272 275 } 273 276 274 277 function h2($matches) 275 278 { 276 279 return "<h2 id=\"".(++self::$header_count)."\">"; 277 280 } 278 281 279 282 function h3($matches) 280 283 { 281 284 return "<h3 id=\"".(++self::$header_count)."\">"; 282 285 } 283 286 284 287 } 285 288
