Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. _________ U S A G E $transform = new Smark([Text-String] $input); echo $transform->textAsHTML(); // getting comments-array $comments = $transform->comments(); ________________________ R E L E A S E N O T E S 1.0 Initial Release - 06.05.2016 ** Newly added features compared to Smark version 1 ** - text-comments which will be removed in the final rendering - additionally Comments can have keywords to seperate the different aspects - accessto comments $comments["key"] - definitin lists, a really nice form of lists - way more options to add tables and to style them - no transform-markup - ordered lists - markup to create divs - markup to create spans - markup to create paragraphs - auto-creation of paragraphs - option to add css-classes or styles to block-markup (div, span, blockquote, tables) of text - references with custom text instead of numbers - subscript-markup added - wiki-style linking, set up a root [![rootpath/index.phpßarticle=]!] - [[Oranges]] --> Oranges - [[Oranges::Article about Oranges]] --> Article about Oranges ** Changes ** - underlined-markup now formatted with instead of text and requires now double underline __underlined text__ - table of contents, only headlines after set markup will be included - inverse, instead of *underline* the markup is now ++underline++ - named links, instead of [display text](URL "alt text") the markup is now [url::display text] - internal custom links, instead of [^ LinkID (Text to display)] the markup is now [^ LinkID::Text to display] - additionally this markup won't transformed to supertext anyore - references, instead of +ref+Text to display+endref+ the markup is now ==Text to display== ** Removed Markup ** - +color+ +endcolor --> use spans and css style instead - +column+ +endcolumn+ --> use divs and css style instead - removed todo-markup --> no replacement available --> !!NOTE!! clearDeprecated() automatically converts most old markup to the new one, no further editing required Exception: ToDo Markup, this will be ignored 1.0.1 - Release Notes 24.05.2017 **Bugfixes** - +html+ +endhtml+ issue fixed, where parsing a document could lead to eternal processing of a document, for some strange reason php dislikes %% characters at the beginning of a line in a string on passing to another variable. Circumventing this issue by using %SAVED-HTML-1% instead of %%SAVED-HTML-1%% 1.0.2 - Release Notes 26.09.2017 **Bugfixes** - resolved an issue for tables with included csv-table - resolvd an issue for code-tag with code that includes html-attributes - resolved an issue where some elements at the beginning of a document wouldn't appear 1.0.3 - Release Notes 10.10.2017 **NEW** - small-markup added °°small text°° produces small text - native recognition for mp4-video and mp3-audio files, like images no additional markup required - +tablefoot+ +endtablefoot+ markup added, works like +tablehead+ markup - +tablebody+ +endtablebody+ markup added, works like +tablehead+ markup **Bugfixes** - resolved an issue with tableofcontent-function which removed original h[1-6] - resolved an issue with tableofcontents when producing the first jump links - resolved an issue with list-transformation where first element is indented - resolved an issue with tables and compact formatting when a line contains empty cells, e.g. value1;value2;;;value5 - resolved bug for tablehead-markup with style, where the inserted style is not clean - resolved bug for list-closing-HTML-tags closing in wrong order - resolved an issue for __underlined__ and --deleted-- markup also performing transformation in urls and paths 1.0.4 - Release Notes 10.09.2018 - improved url-conversion for links and media-files, supports UTF-8 (äöü etc.) characters now - improved table of contents generation, correcting list closing-errors - improved table-processing for markup +table|[;]+ and cells containing special characters which needs to be encoded - parsing-error fixed where numbers without trailing dot at the beginning of a line would treated as a list-item 1.0.5 - Release Notes 29.12.2018 - small Fix for PHP 7.2 1.0.6 - Release Notes 25.01.2019 - resolved a blocks-atrribute-issue in quoteCodeTagTransform-function ------------------------------- D E V E L O P E R N O T E S 06.05.2016 - Starting redoing the Smark-Class since I feel it is neccessary, and heck, the first version is more than a half decade old and I learned soe new tricks - Additionally I've included some things I don't want to see anymore, like the todo lists and internal CSS-Styles, output-rendering should be plain HTML - Also there is need to beef up Smark drastically to stand up against the competition like MultiMarkdown and Textile */ class Smark { var $text = ""; var $htmlOutput = ""; var $comments = ""; var $htmlSave = array(); var $saveForLaterReturn = array(); var $javaSciptLinksOn = true; var $javaScriptHashStart; var $javaScriptHashEnd; var $rootLink = ""; var $textBundleBase = ""; function __construct($ressource) { $ressource = str_replace(" ", "\t", $ressource); // replacing stupid 4Space indention with tabs $ressource = $ressource."\n\n"; $this->text = $ressource; $this->htmlOutput = $ressource; if($this->javaSciptLinksOn) { $this->javaScriptHashStart = "javascript:;\" onclick=\"document.location.hash='"; $this->javaScriptHashEnd = "';"; } else { $this->javaScriptHashStart = "#"; $this->javaScriptHashEnd = ""; } // $this->performTransformation(); } function textAsHTML() { return $this->htmlOutput; } function comments() { return $this->comments; } function textbundleBase($baseURL){ $this->textBundleBase = $baseURL."/"; } function performTransformation() { $this->escapeCharacters(); $this->commentedText(); $this->saveHTML(); $this->clearDeprecated(); $this->getRootLink(); $this->urlTransform(); $this->performHTMLEntities(); $this->inlineRegexTransformation(); $this->referenceTransform(); $this->quoteCodeTagTransform(); $this->tableOfContentsTransform(); $this->tableTransfrom(); $this->definitionListTransForm(); $this->listTransform(); $this->returnSavedPieces(); $this->makeParagraphs(); $this->autoLineBreaks(); $this->returnHTML(); $this->resolveEscapedCharacters(); } private function urlTransform(){ $entitySaveCounter = 1; /* Images with alignment */ $pattern = '/(?((left|right|center))/is'; // image-aligneed preg_match_all($pattern, $this->htmlOutput, $result); for($i = 0; $i < count($result[0]); $i++) { $replaceString = ''; $marker = "%%URL-SAVE-".$entitySaveCounter."%%"; $this->saveForLaterReturn[$marker] = $replaceString; $this->htmlOutput = str_replace($result[0][$i], $marker, $this->htmlOutput); $entitySaveCounter++; } /* Simple images, videos and audio */ $patterns[0]["pattern"] = '/(?'; $patterns[1]["pattern"] = '/(?Not supported'; $patterns[2]["pattern"] = '/(?Not supported'; foreach($patterns as $pattern) { $thePattern = $pattern["pattern"]; // echo $thePattern; preg_match_all($thePattern, $this->htmlOutput, $result); for($i = 0; $i < count($result[0]); $i++){ $replaceString = str_replace("URL", $result[0][$i], $pattern["template"]); $marker = "%%URL-SAVE-".$entitySaveCounter."%%"; $this->saveForLaterReturn[$marker] = $replaceString; $this->htmlOutput = str_replace($result[0][$i], $marker, $this->htmlOutput); $entitySaveCounter++; } } /* Advanced URLS [www.the.url::Some Text] */ $pattern = '/\[(.*?)::(.*?)\]/i'; preg_match_all($pattern, $this->htmlOutput, $result); for($i = 0; $i < count($result[0]); $i++) { $replaceString = ''.htmlentities($result[2][$i]).''; $marker = "%%URL-SAVE-".$entitySaveCounter."%%"; $this->saveForLaterReturn[$marker] = $replaceString; $this->htmlOutput = str_replace($result[0][$i], $marker, $this->htmlOutput); $entitySaveCounter++; } /* Regular URLs */ $pattern = '/(?htmlOutput, $result); for($i = 0; $i < count($result[0]); $i++) { $replaceString = ''.htmlentities($result[0][$i]).''; $marker = "%%URL-SAVE-".$entitySaveCounter."%%"; $this->saveForLaterReturn[$marker] = $replaceString; $this->htmlOutput = str_replace($result[0][$i], $marker, $this->htmlOutput); $entitySaveCounter++; } } private function clearDeprecated() { $pattern = array( '/\*\*\*\*\*(.*?)\*\*\*\*\*/i', '/\*\*\*\*(.*?)\*\*\*\*/i', '/\*\*\*(.*?)\*\*\*/i', '/\[(.*?)\]\(((.*?)) "(.*?)"\)/i', '/ \*([^\*].*?)[^ ]\* /i', '/\+color=([#a-zA-F0-9-]{0,})\/([#a-zA-F0-9-]{0,})\+(.*?)\+endcolor\+/is', '/\+column\+(.*?)\+endcolumn\+/is', '/\+column:([1-9]{1})\+(.*?)\+endcolumn\+/is', '/\[\^ (.*?) \((.*?)\)\]/i', '/\+ref\+/i', '/\+endref\+/i', ); $replace = array( '__**++$1++**__', '**++$1++**', '__$1__', '[$2::$1]', ' ++$1++ ', '+span|style="color:$1; background-color:$2;"+$3+endspan+', '+div|style="-moz-column-count: 3;-moz-column-gap: 1em;-moz-column-rule: 1px solid black;-webkit-column-count: 3;-webkit-column-gap: 1em;-webkit-column-rule: 1px solid black;column-count: 3;column-gap: 1em;column-rule: 1px solid black;text-align: justify;"+$1+enddiv+', '+div|style="-moz-column-count: $1;-moz-column-gap: 1em;-moz-column-rule: 1px solid black;-webkit-column-count: $1;-webkit-column-gap: 1em;-webkit-column-rule: 1px solid black;column-count: $1;column-gap: 1em;column-rule: 1px solid black;text-align: justify;"+$2+enddiv+', '[^ $1::$2]', '==', '==', ); $this->htmlOutput = preg_replace($pattern, $replace, $this->htmlOutput); } private function getRootLink() { preg_match('/\[\!\[(.*?)\]\!\]/i', $this->htmlOutput, $result); if(trim($result[1]) != "") { $this->rootLink = $result[1]; $this->htmlOutput = preg_replace('/\[\!\[(.*?).\]\!\]/i', '', $this->htmlOutput); } } private function performHTMLEntities() { /* $entitySaveCounter = 1; $returnArray = array(); $patterns[] = '/ *?=".*?"/i'; // styles etc eg. colspan="3" $patterns[] = '/(?((left|right|center))/is'; // image-aligneed $patterns[] = '/(?htmlOutput, $result); for($i = 0; $i < count($result[0]); $i++) { $marker = "%%ENTITY-SAVE-".$entitySaveCounter."%%"; $this->htmlOutput = str_replace($result[0][$i], $marker, $this->htmlOutput); $returnArray[$marker] = $result[0][$i]; $entitySaveCounter++; } } */ // echo $this->htmlOutput; $this->htmlOutput = htmlentities($this->htmlOutput, ENT_COMPAT, "UTF-8"); // ° brauchen wir für small markup $this->htmlOutput = str_replace("°", "°", $this->htmlOutput); // Strike und underline umwandlung hier machen, diese Zeichen können durchaus in urls auftauchen $searchRegex = array('/\_\_(.*?)\_\_/i', # sunderlined '/([^{])--(.*?)--/i', # strike ); $replaceRegex = array('$1', '$1$2', ); $this->htmlOutput= preg_replace($searchRegex, $replaceRegex, $this->htmlOutput); /* $returnArray = array_reverse($returnArray); foreach($returnArray as $key => $value) { $this->htmlOutput = str_replace($key, $value, $this->htmlOutput); } // echo $this->htmlOutput; //echo "
"; 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+", "

$1

\n", "

$1

\n", "

$1

\n", "

$1

\n", "
$1
\n", "
$1
\n", "

$1

\n", '$2', '$1', '$2', ' ', // '$2', // '', // '', // '', // '', // '$1$2', // '$1', '$1', '$1', '
', // '$1$2', '$1$2', '$1$2', '$1', '$1', '
', '
', '', '', '', '', '
', '
', '

', '

', '', ); $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 = "
".$refPiece[1].""; $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 = "
".$ref.""; $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 .= '
  1. '.$result[2][$i].'
  2. '; } $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], "")) && !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], "

    ")) || 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."
    "; $addTabs = str_repeat("\t", $currentLevel); $currentLevel++; $addTabs2 = str_repeat("\t", $currentLevel); if($lineIsOrderedType) { $finalList .= "\n".$addTabs."
      \n"; // $closeListItems[] = $addTabs."
    "; $addTabsToClose = str_repeat("\t", $currentLevel - 1); $closeListItems[] = "
  • \n".$addTabsToClose.""; } else { //echo "Hoer".$currentLevel."--".$thisLevel; $finalList .= "\n".$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
    ".trim($singleDef[0])."
    \n"; for($k = 1; $k < count($singleDef); $k++) { $finalList .= "\t
    ".str_replace("\n", "
    ", trim($singleDef[$k]))."
    \n"; } } $finalList .= "
    "; $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("/(.*?)<\/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 "
    "; 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\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."\n"; $setAttributes = ""; } } else { if($colStart == true) { $theTable .= "\t\n"; $colStart = false; } } } $theTable .= "
    ".$captionText."
    \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 ?>