"; var_dump($returnArray); echo ""; */ } private function returnSavedPieces() { /* echo $this->htmlOutput; echo "
"; var_dump($this->saveForLaterReturn); echo ""; */ // while (strpos($this->htmlOutput, "%%SAVED-") !== false) // { foreach($this->saveForLaterReturn as $key => $value) { $this->htmlOutput = str_replace(trim($key), $value, $this->htmlOutput); } // repeat, in case of double saved-items, very akwards foreach($this->saveForLaterReturn as $key => $value) { $this->htmlOutput = str_replace(trim($key), $value, $this->htmlOutput); } // } } private function inlineRegexTransformation() { $regexMarkdownSearch = array( '/[\s]{0,1}\+tableofcontents\+/i', // removing whitespaces before tag, which can currupt the resulting list '/^[#]{1,1} (.*?)\n/m', '/^[#]{2,2} (.*?)\n/m', '/^[#]{3,3} (.*?)\n/m', '/^[#]{4,4} (.*?)\n/m', '/^[#]{5,5} (.*?)\n/m', '/^[#]{6,6} (.*?)\n/m', '/^(.*?)[ ]*\n(=+)[ ]*\n+/m', // Headline 1 Alt '/\[\[(.*?)::(.*?)\]\]/i', '/\[\[(.*?)\]\]/i', '/\[\^ (.*?)::(.*?)\]/i', # footnote, link with title '/\[\^ (.*?)\]/i', # footnote destination // '/\[(.*?)::(.*?)\]/i', # looks for [example::http://url.com/] // '/(?((left|right|center))/is', # image aligned // '/(? - Tag '/\?\?(.*?)\?\?/i', # for the - Tag '/\+quote\+[\s]{0,1}/i', '/\+endquote\+[\s]{0,1}/i', '/\+code\+[\s]{0,1}/i', '/\+endcode\+[\s]{0,1}/i', '/\+span\+/i', '/\+endspan\+/i', '/\+div\+[\s]{0,1}/i', '/\+enddiv\+[\s]{0,1}/i', '/\+para\+[\s]{0,1}/i', '/\+endpara\+[\s]{0,1}/i', '/\+comment\+/i', '/\+endcomment\+/i', ); $regexMarkdownReplace = array( "\n+tableofcontents+", "
', '', '
',
'
',
'',
'',
'', '
', '', ); $this->htmlOutput= preg_replace($regexMarkdownSearch, $regexMarkdownReplace, $this->htmlOutput); } private function quoteCodeTagTransform() { $pattern = '/\+quote(.*?)\+[\s]{0,}/i'; preg_match_all($pattern, $this->htmlOutput, $result); foreach($result[0] as $single) { $stylePiece = explode("|", trim($single)); if(count($stylePiece) > 1) { $style = substr($stylePiece[1], 0, strlen($stylePiece[1]) - 1); $refPiece = explode(":", $stylePiece[0]); if(count($refPiece) > 1) { $replaceString = ""; $this->htmlOutput = str_replace($single, $replaceString, $this->htmlOutput); } else { $replaceString = ""; $this->htmlOutput = str_replace($single, $replaceString, $this->htmlOutput); } } else { $refPiece = explode(":", trim($single)); if(count($refPiece) > 1) { $ref = substr($refPiece[1], 0, strlen($refPiece[1]) - 1); $replaceString = ""; $this->htmlOutput = str_replace($single, $replaceString, $this->htmlOutput); } } } $tags = array("span", "div", "code", "para"); foreach($tags as $tag) { // [\s]{0,} um lästige newlines loszuwerden $pattern = '/\+'.$tag.'(.*?)\+[\s]{0,}/i'; preg_match_all($pattern, $this->htmlOutput, $result); foreach($result[0] as $single) { $singleRAW = $single; $single = str_replace(""", "\"", $single); $stylePiece = explode("|", $single); if(count($stylePiece) > 1) { $replaceTag = $tag; if($tag == "para") $replaceTag = "p"; $style = substr(trim($stylePiece[1]), 0, strlen(trim($stylePiece[1])) - 1); $replaceString = "<".$replaceTag." ".$style.">"; $this->htmlOutput = str_replace($singleRAW, $replaceString, $this->htmlOutput); } } } } private function referenceTransform() { preg_match_all('/([^{])==(.*?)==/i', $this->htmlOutput, $result); // doppelt gehnanntes soll auf gleiches zeigen // $result[0] = array_unique($result[0]); // $result[1] = array_unique($result[1]); $reference_list = ''; for($i = 0; $i < count($result[0]); $i++) { $number_of_references = $i + 1; $this->htmlOutput = str_replace($result[0][$i], $result[1][$i].'['.($number_of_references).']', $this->htmlOutput); $reference_list .= '
"; $this->htmlOutput = str_replace("+showreferences+", $reference_list, $this->htmlOutput); } private function makeParagraphs() { $addParasToText = explode("\n\n", $this->htmlOutput); for($i = 0; $i < count($addParasToText); $i++) { if(!is_numeric(strpos($addParasToText[$i], "- ↑ '.$result[2][$i].'
'; } $reference_list .= "")) && !is_numeric(strpos($addParasToText[$i], "")) && !is_numeric(strpos($addParasToText[$i], " ")) && !is_numeric(strpos($addParasToText[$i], "
")) && !is_numeric(strpos($addParasToText[$i], "")) && !is_numeric(strpos($addParasToText[$i], " ")) && !trim($addParasToText[$i]) == "" ) { $addParasToText[$i] = "
\n".$addParasToText[$i]."\n
"; } } $this->htmlOutput = implode("\n\n", $addParasToText); } // Ende makeParagraphs() - Methode private function autoLineBreaks() { $addBRToText = explode("\n", trim($this->htmlOutput)); // helper variable to prevent
in Tables $table_open = false; // going through all line for($i = 0; $i < count($addBRToText); $i++) { // check for LineEnding in this line if(is_numeric(strpos($addBRToText[$i], '"))) { $table_open = false; } // finding head and lines
and list elements elseif(is_numeric(strpos($addBRToText[$i], "")) || is_numeric(strpos($addBRToText[$i], "")) || is_numeric(strpos($addBRToText[$i], " ")) || is_numeric(strpos($addBRToText[$i], "
")) || is_numeric(strpos($addBRToText[$i], "")) || is_numeric(strpos($addBRToText[$i], "")) || is_numeric(strpos($addBRToText[$i], " \n".$addTabsToClose.""; } else { //echo "Hoer".$currentLevel."--".$thisLevel; $finalList .= "\n".$addTabs."")) || is_numeric(strpos($addBRToText[$i], "
htmlOutput = implode("\n", $addBRToText); $this->htmlOutput = str_ireplace("
\n", "
", $this->htmlOutput); $this->htmlOutput = str_ireplace("
\n
", "", $this->htmlOutput); } // Ende autoLineBreaks() - Methode private function listTransform() { $patternAll = "/(?m)(^([^A-Za-z ]{0,})([0-9])\.[ \t]{1,}|^([^A-Za-z0-9 ]{0,})([*\-+])[ \t]{1,})(.*?)\n\n/is"; $listCounter = 1; $savedLists = array(); while (preg_match($patternAll, $this->htmlOutput, $result)) { //echo ""; var_dump($result); echo ""; // nl ranhängen, die durch regex rausgelöst wurden $marker = "\n%%SAVED-LIST-".$listCounter."%%\n\n"; $this->htmlOutput = str_replace($result[0], $marker, $this->htmlOutput); $savedLists[$marker] = $result[0]; $listCounter++; } foreach($savedLists as $key => $value) { // $value = trim($value); $listItems = explode("\n", $value); $finalList = ""; $listStarted = false; $currentLevel = 10000; //hohen level voreinstellen, damit der Level des ersten Listenpunkts sicher gefunden werden kann, wenn liste mit tabs beginnt $openSubLists = 0; $closeListItems = array(); $closeListWith = ""; foreach($listItems as $line) { $lineIsOrderedType = false; $line = rtrim($line); $line = str_replace("\t", "", $line, $thisLevel); $firstcharacter = $line[0]; if(strlen($line) > 0) { if($currentLevel == 10000){ $currentLevel = $thisLevel; } $isListItem = false; if(is_numeric($firstcharacter)) { $lineIsOrderedType = true; $isListItem = true; $cutPos = strpos($line, "."); $line = substr($line, $cutPos + 1); } else if($firstcharacter == "*" || $firstcharacter == "-" || $firstcharacter == "+") { $isListItem = true; $line = substr($line, 2); } else // einfach neue Zeile per br anhhängen { $finalList .= "
".$line; } if($isListItem) { if(!$listStarted) { if($lineIsOrderedType) { $finalList .= ""; $closeListWith = "
"; } else { $finalList .= ""; $closeListWith = "
"; } $finalList .= "\n\t".$line; $listStarted = true; } else { if($currentLevel == $thisLevel) { $addTabs = str_repeat("\t", $currentLevel); $finalList .= " \n".$addTabs."".$line; } else if($currentLevel < $thisLevel) { //echo "Hoer".$currentLevel."--".$thisLevel." "; $addTabsToClose = str_repeat("\t", $currentLevel - 1); $closeListItems[] = "
"; $addTabs = str_repeat("\t", $currentLevel); $currentLevel++; $addTabs2 = str_repeat("\t", $currentLevel); if($lineIsOrderedType) { $finalList .= "\n".$addTabs."\n"; // $closeListItems[] = $addTabs."
\n"; $addTabsToClose = str_repeat("\t", $currentLevel - 1); $closeListItems[] = "\n".$addTabsToClose."
"; } $finalList .= $addTabs2."".$line; $openSubLists++; } else if($currentLevel > $thisLevel) { $counterForClosinglists = $thisLevel; $doAddCloseItems = false; while ($counterForClosinglists < $currentLevel) { $doAddCloseItems = true; $counterForClosinglists++; $addItem = array_pop($closeListItems); $finalList .= $addItem; } if($doAddCloseItems) { $finalList .= "\n"; } $currentLevel = $thisLevel; $addTabs = str_repeat("\t", $currentLevel); $finalList .= $addTabs." ".$line; } } } } } $finalList .= " \n"; while(count($closeListItems) > 0) { $addItem = array_pop($closeListItems); $finalList .= $addItem."\n"; } $finalList .= $closeListWith; $finalList .= "\n"; $this->saveForLaterReturn[$key] = $finalList; } } // Ende Methode listTransform private function definitionListTransForm() { // dl dt dd $patternAll = "/(?m)^([^A-Za-z\t ]{0,})(\:\:)[ \t]{0,}(.*?)\n\n/is"; $listCounter = 1; $savedLists = array(); while (preg_match($patternAll, $this->htmlOutput, $result)) { // nl ranhängen, die durch regex rausgelöst wurden $marker = "\n%%SAVED-DEFLIST-".$listCounter."%%\n\n"; $this->htmlOutput = str_replace($result[0], $marker, $this->htmlOutput); $savedLists[$marker] = $result[0]; $listCounter++; } foreach($savedLists as $key => $value) { $finalList = "\n"; $value = trim($value); $definitions = explode("::", $value); array_shift($definitions); for($i = 0; $i < count($definitions); $i++) { $singleDef = explode("\n:", $definitions[$i]); $finalList .= "\t
"; $this->saveForLaterReturn[$key] = $finalList; } } // Ende der Metode definitionListTransForm() private function tableOfContentsTransform() { $position = strpos($this->htmlOutput, "+tableofcontents+"); if($position !== false) { $seekInString = substr($this->htmlOutput, $position); preg_match_all("/- ".trim($singleDef[0])."
\n"; for($k = 1; $k < count($singleDef); $k++) { $finalList .= "\t- ".str_replace("\n", "
\n"; } } $finalList .= "
", trim($singleDef[$k]))."(.*?)<\/h[1-6]{1,1}>/", $seekInString, $result); if(count($result[0]) > 1) { $tocCounter = 1; // number of items in toc, needed for javascript $toc = ""; // toc to be displayed $opencounter = 0; // counter for the number of open ul-list-items $currentLevel = 0; // sets the level determined by header-tag for($i = 0; $i < count($result[0]); $i++) { $addTabs = 0; $itemLevel = (int)$result[1][$i]; // sub-list detected if($itemLevel > $currentLevel){ while($currentLevel < $itemLevel){ $toc .= str_repeat("\t", $currentLevel)." \n"; $opencounter++; $currentLevel++; } } // next item is higher, closing sub lists else if($itemLevel < $currentLevel){ while($currentLevel > $itemLevel){ $toc .= str_repeat("\t", $itemLevel)."
\n"; $currentLevel--; $opencounter--; } } //Adding item to table of contents $theLink = "javaScriptHashStart."toc-".$tocCounter.$this->javaScriptHashEnd."\">".$result[2][$i].""; $toc .= str_repeat("\t", $currentLevel)."".$theLink." \n"; // setting jump-link marker within text $replaceHeader = "".$result[2][$i]." "; $pos = strpos($this->htmlOutput, $result[0][$i]); $this->htmlOutput = substr_replace($this->htmlOutput, $replaceHeader, $pos, strlen($result[0][$i])); $tocCounter++; } // closing open-lists if($opencounter > 0){ $itemLevel -= 1; while($opencounter > 0){ $toc .= str_repeat("\t", $itemLevel)."\n"; $opencounter--; $itemLevel--; } } } $this->htmlOutput = str_replace("+tableofcontents+", $toc, $this->htmlOutput); } } private function saveHTML() { preg_match_all('/\+html\+(.*?)\+endhtml\+/is', $this->htmlOutput, $results); $htmlCounter = 1; for ($i = 0; $i < count($results[0]); $i++) { $marker = "%SAVED-HTML-".$htmlCounter."%"; $result = str_replace($results[0][$i], $marker, $this->htmlOutput); $this->htmlOutput = $result; $htmlCounter++; $this->htmlSave[$marker] = $results[1][$i]; } preg_match_all('/@@(.*?)@@/i', $this->htmlOutput, $results); for ($i = 0; $i < count($results[0]); $i++) { $marker = "%SAVED-HTML-".$htmlCounter."%"; $this->htmlOutput = str_replace($results[0][$i], $marker, $this->htmlOutput); $htmlCounter++; $this->htmlSave[$marker] = $results[1][$i]; } } private function returnHTML() { // echo "Hallo"; var_dump($this->htmlSave); echo ""; foreach($this->htmlSave as $key => $value) { $this->htmlOutput = str_replace(trim($key), $value, $this->htmlOutput); } } private function escapeCharacters() { $escapeCharacters = array( "%%01%%" => "\\\\", "%%02%%" => "\\*", "%%03%%" => "\\_", "%%04%%" => "\\{", "%%05%%" => "\\}", "%%ß6%%" => "\\(", "%%07%%" => "\\)", "%%08%%" => "\\[", "%%09%%" => "\\]", "%%10%%" => "\\>", "%%11%%" => "\\#", "%%12%%" => "\\.", "%%13%%" => "\\!", "%%14%%" => "\\+", "%%15%%" => "\\-", "%%16%%" => "\\:", "%%17%%" => "\\$", "%%18%%" => "\\@", "%%19%%" => "\\=", "%%20%%" => "\\?", ); foreach($escapeCharacters as $key => $value) { $this->htmlOutput = str_replace($value, $key, $this->htmlOutput); } } private function resolveEscapedCharacters() { $escapeCharacters = array( "%%01%%" => "\\", "%%02%%" => "*", "%%03%%" => "_", "%%04%%" => "{", "%%05%%" => "}", "%%ß6%%" => "(", "%%07%%" => ")", "%%08%%" => "[", "%%09%%" => "]", "%%10%%" => ">", "%%11%%" => "#", "%%12%%" => ".", "%%13%%" => "!", "%%14%%" => "+", "%%15%%" => "-", "%%16%%" => ":", "%%17%%" => "$", "%%18%%" => "@", "%%19%%" => "=", "%%20%%" => "?", ); foreach($escapeCharacters as $key => $value) { $this->htmlOutput = str_replace($key, $value, $this->htmlOutput); } } private function tableTransfrom() { $saveTableObjects = ""; preg_match_all('/\+table(.*?)\+(.*?)\+endtable\+/is', $this->htmlOutput, $results); if(is_array($results)) { $tableCounter = 1; for($i = 0; $i < count($results[0]); $i++) { $results[2][$i] = html_entity_decode($results[2][$i]); // echo $results[2][$i]; $colDivider = ""; $tableAttributes = ""; $attributes = array(); $tableStyle = ""; $tableAttributes = substr(trim($results[1][$i]), 1, strlen($results[1][$i])-1); ## NOTLÖSUNNG - ENTITIES schon codiert $tableAttributes = str_replace(">", ">", $tableAttributes); $attributes = explode("|", $tableAttributes); if(count($attributes) > 1 && strpos($attributes[count($attributes) - 1], "]") === false) { $tableStyle = array_pop($attributes); $reglue = implode("|", $attributes); if(strpos($reglue, "[") === 0) { //$colDivider = substr($reglue, 1, strlen($reglue) - 2); //echo $reglue; $checkFile = explode("]->", $reglue); //echo ""; var_dump($checkFile); echo ""; if(count($checkFile) > 1) { $tableData = file_get_contents($this->textBundleBase.$checkFile[1]); $results[2][$i] .= "\n".$tableData."\n"; $colDivider = substr($checkFile[0], 1); } else { $colDivider = substr($reglue, 1, strlen($reglue) - 2); } } } else if (strpos($tableAttributes, "[") === 0) { $checkFile = explode("]->", $tableAttributes); if(count($checkFile) > 1) { $tableData = file_get_contents($this->textBundleBase.$checkFile[1]); $results[2][$i] .= "\n".$tableData."\n"; $colDivider = substr($checkFile[0], 1); } else { $colDivider = substr($tableAttributes, 1, strlen($tableAttributes) - 2); } } else $tableStyle = $tableAttributes; if(strlen($tableStyle) > 0) $theTable = "\n"; else $theTable = "
\n"; $pieces = explode("\n", $results[2][$i]); //echo "
\n"; $marker = "%%SAVED-TABLES-".$tableCounter."%%"; $tableCounter++; $this->htmlOutput = str_replace($results[0][$i], $marker, $this->htmlOutput); $this->saveForLaterReturn[$marker] = $theTable; } } } // Ende Methode tableTransfrom() private function commentedText() { $this->comments = array(); $pattern = '/((?>^[ ]*\$[ ]?.+\n(.+\n)*\n*)+)/xm'; preg_match_all($pattern, $this->htmlOutput, $result); for($i = 0; $i < count($result[0]); $i++) { $keyword = "Comments"; $pieces = explode("\n", $result[0][$i]); // nach Keywordd suchen for($y = 0; $y < count($pieces); $y++) { $line = trim($pieces[$y]); if(strpos($line, '$$') === 0) { $keyword = trim(substr($line, 2)); } else { if(strpos($line, '$') === 0 ) { $line = trim(substr($line, 1)); } if($line != "") $this->comments[$keyword][] = $line; } } $this->htmlOutput = str_replace($result[0][$i], "", $this->htmlOutput); } }// Ende Methode commentedText() } // Ende Klasse Smark ?>"; var_dump($pieces); echo ""; if($colDivider != "") { $newPieces = array(); for($y = 0; $y < count($pieces); $y++) { if(trim($pieces[$y]) != ""){ if(strpos(trim($pieces[$y]), "+tablehead") === 0 || trim($pieces[$y]) == "+endtablehead+" || strpos(trim($pieces[$y]), "+tablefoot") === 0 || trim($pieces[$y]) == "+endtablefoot+" || strpos(trim($pieces[$y]), "+tablebody") === 0 || trim($pieces[$y]) == "+endtablebody+" ) { array_push($newPieces, $pieces[$y]); } // else if(trim($pieces[$y]) == "+endtablehead+") // array_push($newPieces, $pieces[$y]); else { $singles = explode($colDivider, $pieces[$y]); for($z = 0; $z < count($singles); $z++) { if(trim($singles[$z]) == "") $singles[$z] = " "; array_push($newPieces, $singles[$z]); } array_push($newPieces, " "); } } } $pieces = $newPieces; } $colStart = false; //echo ""; var_dump($pieces); echo ""; for($j = 0; $j < count($pieces); $j++) { if(trim($pieces[$j]) != "" ) { if(strpos(trim($pieces[$j]), "+caption:") === 0) { $captionText = substr(trim($pieces[$j]), 9, strlen($pieces[$j]) - 10); $theTable .= "\t".$captionText." \n"; } elseif(strpos(trim($pieces[$j]), "+tablehead") === 0 || strpos(trim($pieces[$j]), "+tablefoot") === 0 || strpos(trim($pieces[$j]), "+tablebody") === 0 ) { $theTag = substr($pieces[$j], 6, 4); $checkForStyle = explode("|", $pieces[$j]); if(count($checkForStyle) > 1) // note; wenn substr eine negative länge verwendet wird, wird das Ende abgeschnitten $theTable .= "\t\n"; else $theTable .= "\t \n"; $colStart = false; } elseif(strstr(trim($pieces[$j]), "+endtablehead+") || strstr(trim($pieces[$j]), "+endtablefoot+") || strstr(trim($pieces[$j]), "+endtablebody+") ) { $theTag = substr(trim($pieces[$j]), 9, 4); $theTable .= "\t \n"; $colStart = false; } else if(strstr($pieces[$j], "=\"") && !strstr($pieces[$j], "href=\"") && !strstr($pieces[$j], "src=\"")) // cell-style { $setAttributes = " ".$pieces[$j]; //" align=\"".$alignMent[1]."\""; } // normale Zeilen else { // echo "Hier"; $cellText = trim($pieces[$j]); $tag = "td"; if(strpos($cellText, "!!") === 0) { $cellText = substr($cellText, 2); $tag = "th"; } if($colStart == false) { $theTable .= "\t\n"; $colStart = true; } // set HTML Entities, keep Tags intact $countElements = count(explode(">", $cellText)); // are tags inside? if($countElements > 1){ if($countElements == 3){ $puretextRaw = strip_tags($cellText); $puretextDone = htmlentities($puretextRaw); $cellText = str_replace($puretextRaw, $puretextDone, $cellText); } // there are multiple tags inside this cell else{ $c_Pieces = explode(">", $cellText); for($q = 0; $q < count($c_Pieces) - 1; $q++) { $c_Pieces[$q] = strip_tags($c_Pieces[$q].">"); $cellText = str_replace($c_Pieces[$q], htmlentities($c_Pieces[$q]), $cellText); } } } else{ $cellText = htmlentities($cellText); } $theTable .= "\t\t<".$tag.$setAttributes.">".$cellText."".$tag.">\n"; $setAttributes = ""; } } else { if($colStart == true) { $theTable .= "\t \n"; $colStart = false; } } } $theTable .= "