4 * vp8_doc_tools.php - Functions used when generating the
5 * On2 VP8 user documentation.
10 * http://michelf.com/projects/php-markdown/extra/
13 * http://michelf.com/projects/php-smartypants/
16 * http://qbnz.com/highlighter/
19 * http://tinyurl.com/asciimathphp
22 * http://search.cpan.org/~fvulto/HTML-Toc-0.91/Toc.pod
25 * April 2009 - Lou Quillio <lou.quillio@on2.com>
27 **********************************************************/
31 include_once('PHP-Markdown-Extra-1.2.3/markdown.php');
32 include_once('PHP-SmartyPants-1.5.1e/smartypants.php');
33 include_once('ASCIIMathPHP-2.0/ASCIIMathPHP-2.0.cfg.php');
34 require_once('ASCIIMathPHP-2.0/ASCIIMathPHP-2.0.class.php');
35 include_once('geshi/geshi.php');
39 $geshi_lang = 'geshi/geshi/'; // GeSHi language files
40 $toc_script = './do_toc.pl';
46 * http://tinyurl.com/ASCIIMathPHP
48 * @PARAM mtch_arr array - Array of ASCIIMath expressions
49 * as returned by preg_replace_callback([pattern]). First
50 * dimension is the full matched string (with delimiter);
51 * 2nd dimension is the undelimited contents (typically
54 **********************************************************/
56 function ASCIIMathPHPCallback($mtch_arr)
58 $txt = trim($mtch_arr[1]);
62 if (!isset($asciimath)) $asciimath = new ASCIIMathPHP($symbol_arr);
64 $math_attr_arr = array('displaystyle' => 'true');
66 $asciimath->setExpr($txt);
67 $asciimath->genMathML($math_attr_arr);
69 return($asciimath->getMathML());
75 * ASCIIMath pretty-prints its output, with linefeeds
76 * and tabs. Causes unexpected behavior in some renderers.
77 * This flattens <math> blocks.
79 * @PARAM page_body str - The <body> element of an
80 * XHTML page to transform.
82 **********************************************************/
84 function fix_asciiMath($page_body)
88 // Remove linefeeds and whitespace in <math> elements
89 $tags_bad = array('/(<math.*?>)\n*\s*/'
90 , '/(<mstyle.*?>)\n*\s*/'
91 , '/(<\/mstyle>)\n*\s*/'
92 , '/(<mrow.*?>)\n*\s*/'
93 , '/(<\/mrow>)\n*\s*/'
100 , '/(<mtext.*?>)\n*\s*/'
101 , '/(<\/mtext>)\n*\s*/'
102 , '/(<msqrt.*?>)\n*\s*/'
103 , '/(<\/msqrt>)\n*\s*/'
104 , '/(<mfrac.*?>)\n*\s*/'
105 , '/(<\/mfrac>)\n*\s*/'
107 $tags_good = array( '$1'
125 $out = preg_replace($tags_bad, $tags_good, $page_body);
132 * do_geshi() - Performs GeSHi transforms on XHTML blobs
134 * @param $blob str - The blob to transform
135 * @param $open str - Opening expression to match
136 * @param $close str - Closing expression to match
137 * @param $lang str - Language file to use
139 **********************************************************/
141 function do_geshi($blob, $open = '<pre>',
142 $close = '</pre>', $lang = 'c')
145 $regexp = '|' . $open . '(.*?)' . $close . '|si';
146 echo $regexp . "\n\n";
148 while (preg_match($regexp, $blob, $matches))
150 $geshi = new GeSHi($matches[1], $lang);
151 $geshi->set_language_path($geshi_lang);
152 $blob_new = $geshi->parse_code();
153 // Strip annoying final <br />
154 $blob_new = preg_replace('/\n <\/pre>/', '</pre>' , $blob_new);
155 // Fix annoying GeSHI-injected attributes
156 $blob_new = preg_replace('/<pre.*>/i', '<pre>' , $blob_new);
157 $blob = preg_replace($regexp, $blob_new, $blob, 1);
169 * prep_dd_codeblocks()
171 * I'm _so_ not proud of this, but don't have time to
172 * write a proper regex.
174 * @TODO - Write that regex.
176 **********************************************************/
178 function prep_dd_codeblocks($page_body)
184 while (preg_match($regexp, $page_body))
188 $regexp = '/:\s*~{3,}\s*\n/';
189 $page_body = preg_replace($regexp, ': <pre><code>', $page_body, 1);
194 $regexp = '/\n\s*~{3,}/';
195 $page_body = preg_replace($regexp, '</code></pre>', $page_body, 1);
201 $regexp = '/\n\s*~{3,}/';
202 $page_body = preg_replace($regexp, '</code></pre>', $page_body, 1);