public static function process($strHTML) { $html = $strHTML; //$arr = Wiki2html::get_pres('<pre class="brush: js">p111</pre>...<pre class="brush: css">p222</pre>'); //var_dump($arr); $arr = Wiki2html::get_pre_tags($html); for ($i = 0, $cnt = count($arr); $i < $cnt; $i++) { $html = str_replace( $arr[$i]['pretag'].$arr[$i]['content'].'</pre>', '!pre'.$i.'!', $html); } // Wiki2html Parser $html = html_entity_decode($html); $html = str_replace('–','-',$html); $html = str_replace('"','"',$html); $html = preg_replace('/\&(nbsp);/','&${1};',$html); $html = convertTables($html); $html = simpleText("\n".$html); $tmp = preg_match_all("/!pre(\d)!/s", $html, $patterns); //var_dump($patterns); for ($i = 0, $cnt = count($patterns[1]); $i < $cnt; $i++) { $precontent = html_entity_decode($arr[$i]['content2']); $precontent = str_replace('<', '<', $precontent); // to prevent output <?php $precontent = str_replace('>', '>', $precontent); $html = str_replace('!pre'.$i.'!', "\n".$arr[$i]['pretag'].$precontent.'</pre>', $html); } return $html; }
private static function convertTable($intext) { $text = $intext; $lines = explode("\n", $text); $intable = false; //var_dump($lines); foreach ($lines as $line) { $line = trim($line); if (substr($line, 0, 1) == '{') { //begin of the table $stuff = explode('| ', substr($line, 1), 2); $tableopen = true; $table = "<table " . $stuff[0] . ">\n"; } else { if (substr($line, 0, 1) == '|') { // table related $line = substr($line, 1); if (substr($line, 0, 5) == '-----') { // row break if ($thopen) { $table .= "</th>\n"; } if ($tdopen) { $table .= "</td>\n"; } if ($rowopen) { $table .= "\t</tr>\n"; } $table .= "\t<tr>\n"; $rowopen = true; $tdopen = false; $thopen = false; } else { if (substr($line, 0, 1) == '}') { // table end break; } else { // td $stuff = explode('| ', $line, 2); if ($tdopen) { $table .= "</td>\n"; } if (count($stuff) == 1) { $table .= "\t\t<td>" . simpleText($stuff[0]); } else { $table .= "\t\t<td " . $stuff[0] . ">" . simpleText($stuff[1]); } $tdopen = true; } } } else { if (substr($line, 0, 1) == '!') { // th $stuff = explode('| ', substr($line, 1), 2); if ($thopen) { $table .= "</th>\n"; } if (count($stuff) == 1) { $table .= "\t\t<th>" . simpleText($stuff[0]); } else { $table .= "\t\t<th " . $stuff[0] . ">" . simpleText($stuff[1]); } $thopen = true; } else { // plain text $table .= simpleText($line) . "\n"; } } } //echo "<pre>".++$i.": ".htmlspecialchars($line)."</pre>"; //echo "<p>Table so far: <pre>".htmlspecialchars($table)."</pre></p>"; } if ($thopen) { $table .= "</th>\n"; } if ($tdopen) { $table .= "</td>\n"; } if ($rowopen) { $table .= "\t</tr>\n"; } if ($tableopen) { $table .= "</table>\n"; } //echo "<hr />"; //echo "<p>Table at the end: <pre>".htmlspecialchars($table)."</pre></p>"; //echo $table; return $table; }
/** * Smarty {wiki}{/wiki} block plugin * * @param string $content contents of the block * @param object $template template object * @param boolean $ &$repeat repeat flag * @return string content re-formatted */ function smarty_block_wiki($params, $content, $template, &$repeat) { global $smarty, $config_q; require_once $config_q["code_path"] . "/externals/wiki2html_machine/parseRaw.inc.php"; return simpleText($content); }
function parseRaw($title, $page) { putMilestone("ParseRaw start"); $text = getPartBetween($page, '<text xml:space="preserve">', '</text>'); $html = $text; //echo "<!-- " . wordwrap($text,120,"\n",1) . " -->"; // re-html $html = html_entity_decode($html); $html = str_replace('–', '-', $html); $html = str_replace('"', '"', $html); $html = preg_replace('/\\&(nbsp);/', '&${1};', $html); $html = str_replace('{{PAGENAME}}', $title, $html); // Table $html = convertTables($html); $html = simpleText($html); putMilestone("ParseRaw done"); return $html; }