summaryrefslogtreecommitdiff
path: root/buildscripts/texbuilder
diff options
context:
space:
mode:
Diffstat (limited to 'buildscripts/texbuilder')
-rw-r--r--buildscripts/texbuilder/Page2Tex.php86
1 files changed, 70 insertions, 16 deletions
diff --git a/buildscripts/texbuilder/Page2Tex.php b/buildscripts/texbuilder/Page2Tex.php
index 94567816..c8cad6c9 100644
--- a/buildscripts/texbuilder/Page2Tex.php
+++ b/buildscripts/texbuilder/Page2Tex.php
@@ -7,8 +7,8 @@ class Page2Tex
private $_base;
private $_dir;
- private $_verb_find = array('\$','\%', '\{', '\}', "\t");
- private $_verb_replace = array('$', '%', '{','}', " ");
+ private $_verb_find = array('\$','\%', '\{', '\}', "\t",'``');
+ private $_verb_replace = array('$', '%', '{','}', " ",'"');
function __construct($base, $dir, $current='')
{
@@ -24,7 +24,7 @@ class Page2Tex
function escape_verbatim($matches)
{
- return "\begin{verbatim}".str_replace($this->_verb_find, $this->_verb_replace, $matches[2])."\end{verbatim}\n";
+ return "\begin{verbatim}".str_replace($this->_verb_find, $this->_verb_replace, $matches[1])."\end{verbatim}\n";
}
function escape_verb($matches)
@@ -123,23 +123,29 @@ class Page2Tex
function parse_html($page,$html)
{
+
+
$html = preg_replace('/<\/?com:TContent[^>]*>/', '', $html);
- $html = preg_replace('/<\/?p[^<]*>/m', '', $html);
+ $html = preg_replace('/<\/?p [^>]*>/', '', $html);
+ $html = preg_replace('/<\/?p>/', '', $html);
+ $html = preg_replace('/(\s+|\(+|\[+)"/', '$1``', $html);
+
//escape { and }
$html = preg_replace('/([^\s]+){([^}]*)}([^\s]+)/', '$1\\\{$2\\\}$3', $html);
- $html = preg_replace_callback('/<img\s+src="?<%~([^"]*)%>"?[^\\/]*\/>/', array($this, 'include_image'), $html);
+ $html = preg_replace_callback('/<img\s+src="?<%~([^"]*)%>"?[^>]*\/>/', array($this, 'include_image'), $html);
//escape %
$html = str_replace('%', '\%', $html);
//codes
$html = str_replace('$', '\$', $html);
- $html = preg_replace('/<com:TTextHighlighter[^>]*>/', '`1`', $html);
- $html = preg_replace('/<\/com:TTextHighlighter>/', '`2`', $html);
- $html = preg_replace_callback('/(`1`)([^`]*)(`2`)/m', array($this,'escape_verbatim'), $html);
- $html = preg_replace_callback('/(<div class="source">)([^<]*)(<\/div>)/', array($this,'escape_verbatim'), $html);
+
+ $html = preg_replace_callback('/<com:TTextHighlighter[^>]*>((.|\n)*?)<\/com:TTextHighlighter>/', array($this,'escape_verbatim'), $html);
+// $html = preg_replace('/<\/com:TTextHighlighter>/', '`2`', $html);
+// $html = preg_replace_callback('/(`1`)([^`]*)(`2`)/m', array($this,'escape_verbatim'), $html);
+ $html = preg_replace_callback('/(<div class="source">)((.|\n)*?)(<\/div>)/', array($this,'escape_verbatim'), $html);
$html = preg_replace_callback('/(<pre>)([^<]*)(<\/pre>)/', array($this,'escape_verbatim'), $html);
//<code>
@@ -154,8 +160,8 @@ class Page2Tex
'\href{http://www.pradosoft.com/docs/manual/$1/$2.html}{$1.$2 API Reference}', $html);
//text modifiers
- $html = preg_replace('/<b>([^<]*)<\/b>/', '\textbf{$1}', $html);
- $html = preg_replace('/<i>([^<]*)<\/i>/', '\emph{$1}', $html);
+ $html = preg_replace('/<b[^>]*>([^<]*)<\/b>/', '\textbf{$1}', $html);
+ $html = preg_replace('/<i[^>]*>([^<]*)<\/i>/', '\emph{$1}', $html);
$html = preg_replace_callback('/<tt>([^<]*)<\/tt>/', array($this,'texttt'), $html);
//links
@@ -171,11 +177,11 @@ class Page2Tex
$html = preg_replace('/<\/dl>/', '\end{description}', $html);
//item lists
- $html = preg_replace('/<ul>/', '\begin{itemize}', $html);
+ $html = preg_replace('/<ul[^>]*>/', '\begin{itemize}', $html);
$html = preg_replace('/<\/ul>/', '\end{itemize}', $html);
- $html = preg_replace('/<ol>/', '\begin{enumerate}', $html);
+ $html = preg_replace('/<ol[^>]*>/', '\begin{enumerate}', $html);
$html = preg_replace('/<\/ol>/', '\end{enumerate}', $html);
- $html = preg_replace('/<li>/', '\item ', $html);
+ $html = preg_replace('/<li[^>]*>/', '\item ', $html);
$html = preg_replace('/<\/li>/', '', $html);
//headings
@@ -183,14 +189,62 @@ class Page2Tex
$html = preg_replace('/<h2(\s+id="[^"]+")?>([^<]+)<\/h2>/', '\subsection{$2}', $html);
$html = preg_replace('/<h3(\s+id="[^"]+")?>([^<]+)<\/h3>/', '\subsubsection{$2}', $html);
-
+ //div box
+ $html = preg_replace_callback('/<div class="[tipnofe]*?">((.|\n)*?)<\/div>/',
+ array($this, 'mbox'), $html);
+
+ //tabular
+ $html = preg_replace_callback('/<!--\s*tabular:([^-]*)-->\s*<table[^>]*>((.|\n)*?)<\/table>/',
+ array($this, 'tabular'), $html);
$html = html_entity_decode($html);
-
return $html;
}
+ function tabular($matches)
+ {
+ $options = array();
+ foreach(explode(',', $matches[1]) as $string)
+ {
+ $sub = explode('=', trim($string));
+ $options[trim($sub[0])] = trim($sub[1]);
+ }
+
+ $widths = explode(' ',preg_replace('/\(|\)/', '', $options['width']));
+ $this->_tabular_widths = $widths;
+
+ $this->_tabular_total = count($widths);
+ $this->_tabular_col = 0;
+
+ $begin = "\begin{table}[!hpt]\centering \n \begin{tabular}{".$options['align']."}\\hline";
+ $end = "\end{tabular} \n \end{table}\n";
+ $table = preg_replace('/<\/tr>/', '\\\\\\\\ \hline', $matches[2]);
+ $table = preg_replace('/<tr>/', '', $table);
+ $table = preg_replace('/<th>([^<]+)<\/th>/', '\textbf{$1} &', $table);
+ $table = preg_replace_callback('/<td>((.|\n)*?)<\/td>/', array($this, 'table_column'), $table);
+ $table = preg_replace('/<br \/>/', ' \\\\\\\\', $table);
+
+ $table = preg_replace('/&\s*\\\\\\\\/', '\\\\\\\\', $table);
+ return $begin.$table.$end;
+ }
+
+ function table_column($matches)
+ {
+ $width = $this->_tabular_widths[$this->_tabular_col];
+ if($this->_tabular_col >= $this->_tabular_total-1)
+ $this->_tabular_col = 0;
+ else
+ $this->_tabular_col++;
+ return '\begin{minipage}{'.$width.'\textwidth}\vspace{3mm}'.
+ $matches[1].'\vspace{3mm}\end{minipage} & ';
+ }
+
+ function mbox($matches)
+ {
+ return "\n\begin{mybox}\n".$matches[1]."\n\end{mybox}\n";
+ }
+
function get_chapter_label($chapter)
{
return '\hypertarget{'.str_replace(' ', '', $chapter).'}{}';