User:Kevin html2wiki



HTML to wiki converter and tidy program   END; //////////////////////// if (isset($_REQUEST['input'])) {$input=$_REQUEST['input'];}; if (isset($_REQUEST['output'])) {$output=$_REQUEST['output'];}; ///////////////////////////////////////////////////////////////////////////// //converting engine if ($debug) { $input=<<$output "; $output=preg_replace("#<([a-z]{1,})\s.*>#mUi","<$1>",$output);//Victory = U = non greedy matching //#<([a-z]{1,})\s.*>#Ui
 * 1) first strip out all the new lines
 * 2) then strip out all the rubbish between tags

//Headings//////////////////////////////////////////////////////////// $output=preg_replace("# (.*) #Umi","=$1=\n",$output);//heading 1 $output=preg_replace("# (.*) #Umi","==$1==\n",$output);//heading 2 $output=preg_replace("# (.*) #Umi","===$1===\n",$output);//heading 3 $output=preg_replace("# (.*) #Umi","====$1====\n",$output);//heading 4 $output=preg_replace("# (.*) #Umi","=====$1=====\n",$output);//heading 5

//BOLD ITALIC PRE///////////////////////////////////////////////////// $output=preg_replace("#(.*)#Umi","$1",$output);//bold $output=preg_replace("#(.*)#Umi","$1",$output);//bold //PRE? //Tables////////////////////////////////////////////////////////////// $output=preg_replace("# #i","\n|}",$output);//close table: $output=preg_replace("# #mi","\n|-\n",$output);//table row: $output=preg_replace("# #mi","\n! ",$output);//table heading: $output=preg_replace("# #mi","\n| ",$output);//table data //TODO: colspan
 * 1) next convert table tags to wiki mark up

//lists////////////////////////////////////////////////////////////// //or cheat - just convert all li to * and remove all other nasty tags! $output=preg_replace("##mi","* ",$output);//table data
 * 1) parse through the code
 * 2) start with bullets as default
 * 3) find a ol or ul stag
 * 4) count depth - build up a string with the bullet or number tags
 * 5) next covertt li tags to what ever - pop off stack once finished.
 * 6) Remove all other tags...

//Para's////////////////////////////////////////////////////////////// $output=preg_replace("# #mi","__PARAGRAPH__",$output); $output=preg_replace("# #mi","__PARAGRAPH__",$output);

//clean up//////////////////////////////////////////////////////////// $output=preg_replace("#<.*>#U","",$output);//get rid of all other tags //get rid of too many double blank lines $output=preg_replace("#[\n\s]{2,}#","\n",$output);//remove excess space $output=preg_replace("#\{\|\n\|-#m","{| class=\"wikitable\" ",$output);// remove initial row and set sytle $output=preg_replace("#\s{1,}\n#m","\n",$output);//remove one or more spaces at end of lines //Para part 2//////////////////////////////////////////////////////// $output=preg_replace("#^(!\s|\|\s)__PARAGRAPH__#m","$1",$output); $output=preg_replace("#__PARAGRAPH__#","\n\n",$output);

//DEBUG/////////////////////////////////////////////////////////////// if ($debug==true) {if ($output==$test) echo "Victory! "; else {echo "Failure! "; echo htmlentities($output)." ".htmlentities($test)." "; echo strlen($output)." ".strlen($test)." "; } }; //converting engine end ///////////////////////////////////////////////////////////////////////////// $input=htmlentities($input);//make websafe $output=htmlentities($output); echo ""; echo "Input Box $input Output box $output "; echo ""; echo " "; ?>