public static function toTex($text) { if ($text == '') { return ''; } if ($text == null) { return ''; } //var_dump($text); $pattern = '/(\\[\\[(Category:)((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\])/'; preg_match($pattern, $text, $out); if (count($out) > 0) { $replacement = ''; $text = preg_replace($pattern, $replacement, $text); } $pattern = '/\\[\\[(:)?((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+):((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\|((\\w|\\d|\\s|\\/|\\-|\\.|\\#|\')+)\\]\\]/'; $replacement = '\\wikiref{\\2:\\4}{\\6}'; $text = preg_replace($pattern, $replacement, $text); $pattern = '/\\[\\[(:)?((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+):((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\|((\\w|\\d|\\s|\\/|\\-|\\.|\\#|\')+)\\]\\]/'; $replacement = '\\wikiref{\\2:\\4}{\\6}'; $text = preg_replace($pattern, $replacement, $text); // --- recognize specific links --- $pattern = '/\\[\\[(Technology:)((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/'; $replacement = '\\wikitref{\\2}'; $text = preg_replace($pattern, $replacement, $text); $pattern = '/\\[\\[(Language:)((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/'; $replacement = '\\wikilref{\\2}'; $text = preg_replace($pattern, $replacement, $text); $pattern = '/\\[\\[(101feature:)((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/'; $replacement = '\\wikifref{\\2}'; $text = preg_replace($pattern, $replacement, $text); $pattern = '/\\[\\[(101implementation:)((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/'; $replacement = '\\wikiiref{\\2}'; $text = preg_replace($pattern, $replacement, $text); $pattern = '/\\[\\[(101companies:)((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/'; $replacement = '\\wikicref{\\2}'; $text = preg_replace($pattern, $replacement, $text); //---------------------------------------------------------- $pattern = '/\\[\\[(:)?((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+):((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/'; $replacement = '\\wikiref{\\2:\\4}{\\4}'; $text = preg_replace($pattern, $replacement, $text); $pattern = '/\\[\\[((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/'; $replacement = '\\wikiref{\\1}{\\1}'; $text = preg_replace($pattern, $replacement, $text); $pattern = '/\\[\\[((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\|((\\w|\\d|\\s|\\/|\\-|\\.|\\#)+)\\]\\]/'; $replacement = '\\wikiref{\\1}{\\3}'; $text = preg_replace($pattern, $replacement, $text); $pattern = '/\\[http\\:\\/\\/(([^\\s])*)\\s*(.+)\\]/'; $replacement = '\\href{http://\\1}{\\3}'; $text = preg_replace($pattern, $replacement, $text); $pattern = '/\\[http\\:\\/\\/(([^\\s])*)\\]/'; $replacement = '\\href{http://\\1}{http://\\1}'; $text = preg_replace($pattern, $replacement, $text); $pattern = '/<pre>((\\s*|.|\\s)*)<\\/pre>/'; preg_match($pattern, $text, $out); if (count($out) > 0) { $fname = uniqid("f") . ".ext"; global $filesFolder; $f = fopen($filesFolder . $fname, "w+"); fwrite($f, trim($out[1])); fclose($f); $pattern = '/<pre>((\\s*|.|\\s)*)<\\/pre>/'; $replacement = '\\lstinputlisting[xleftmargin=20pt]{\\texgen/files/' . $fname . "}"; /* \begin{lstlisting} put your code here \end{lstlisting} $replacement = "\begin{lstlisting}" + trim($out[1]) + "end{lstlisting}"; */ $text = preg_replace($pattern, $replacement, $text); } $pattern = '/<syntaxhighlight lang=\\"make" enclose=\\"none\\">(.*)<\\/syntaxhighlight>/'; $replacement = '\\begin{ttfamily}\\1\\end{ttfamily}'; $text = preg_replace($pattern, $replacement, $text); $sfURL = 'https://github.com/101companies/101implementations/blob/master/'; $text = str_replace(" line>", ">", $text); $pattern = '/<syntaxhighlight lang=\\"([a-zA-Z]*)\\"(\\s*(source=\\"(.*)\\")?\\s*)>((\\s*|.|\\s)*)<\\/syntaxhighlight>/'; preg_match_all($pattern, $text, $matches, PREG_SET_ORDER); foreach ($matches as $match) { //var_dump($matches); //echo PHP_EOL; $fname = uniqid("f") . ".ext"; global $filesFolder; $sourceText = ''; #if ($match[4] != null && $match[4]!= ''){ # $link = $sfURL.$match[4]; # $name = end(explode('/',$match[4])); # $sourceText = ', caption={\\href{'.$link.'}{'.$name.'}}'; #} $f = fopen($filesFolder . $fname, "w+"); fwrite($f, trim($match[5])); fclose($f); $pattern = '<syntaxhighlight lang="' . $match[1] . '"' . $match[2] . '>' . $match[5] . '</syntaxhighlight>'; // removed style attribute from the line below: , style=' . $match[1] . ' // we need javascript support for the 101explorer paper if ($match[1] == "javascript") { $replacement = '\\lstinputlisting[xleftmargin=20pt language=javascript ' . $sourceText . ']{\\texgen/files/' . $fname . "}"; //, language=' . $match[1] .$sourceText. //../../files/ } else { $replacement = '\\lstinputlisting[xleftmargin=20pt ' . $sourceText . ']{\\texgen/files/' . $fname . "}"; //, language=' . $match[1] .$sourceText. //../../files/ #$replacement = "\begin{lstlisting}" + trim($match[5]) + "end{lstlisting}"; } $text = str_replace($pattern, $replacement, $text); } /* $text = str_replace($pattern, $match[5], $text); //av: quick fix by Thomas $text = str_replace('lang="haskell" enclose="none">','lang="haskell">', $text); $text = str_replace('lang="haskell" enclose="none">','lang="haskell">', $text); */ $pattern = '/(<syntaxhighlight lang=\\"([a-zA-Z]*)\\" enclose=\\"none\\">)((\\s*|.|:|=|>|<|\\s|\\(|\\)|\\[|\\]|\\{|\\})*)(<\\/syntaxhighlight>)/'; preg_match_all($pattern, $text, $matches, PREG_SET_ORDER); foreach ($matches as $match) { //var_dump($match); $replacement = '\\begin{ttfamily}' . $match[3] . '\\end{ttfamily}'; $text = str_replace($match[0], $replacement, $text); } $text = str_replace('&', '\\&', $text); $text = str_replace('<nowiki>', '', str_replace('</nowiki>', '', $text)); $text = str_replace('$', '\\$', $text); $text = formatter::handleCites($text); $text = formatter::handleBoldAndItalicSpecialCase($text); //we need this because regex cannot handle -> ''' $text = formatter::italic2Textit($text); $text = formatter::handleBold($text); $text = str_replace('->', '$\\rightarrow$', $text); $text = str_replace('=>', '$\\Rightarrow$', $text); $text = str_replace('<', '$<$', $text); $text = str_replace('>', '$>$', $text); $text = str_replace('%', '\\%', $text); $text = str_replace("<references>", "", $text); $text = str_replace("<references/>", "", $text); $text = str_replace('^', '\\^', $text); $text = formatter::nestedList($text); $text = formatter::subsubsubsections($text); $text = formatter::subsubsections($text); $text = escape($text); $res = handleUmlauts($text); //var_dump($res); return trim($res); }
function toTexMacro() { $tex = "\\newcommand{\\" . getTexCommandName($this->getTitle()) . "ImplementationTitle}{\\wikiiref{" . $this->getTitle() . "}}" . PHP_EOL; $tex .= "\\newcommand{\\" . getTexCommandName($this->getTitle()) . "ImplementationIntent}{" . ucfirst(formatter::toTex($this->intent)) . "}" . PHP_EOL; $tex .= "\\newcommand{\\" . getTexCommandName($this->getTitle()) . "ImplementationMotivation}{" . formatter::toTex($this->motivation) . "}" . PHP_EOL; $tex .= "\\newcommand{\\" . getTexCommandName($this->getTitle()) . "ImplementationLanguages}{" . formatter::toTex($this->languages) . "}" . PHP_EOL; $tex .= "\\newcommand{\\" . getTexCommandName($this->getTitle()) . "ImplementationTechnologies}{" . formatter::toTex($this->technologies) . "}" . PHP_EOL; $tex .= "\\newcommand{\\" . getTexCommandName($this->getTitle()) . "ImplementationIllustration}{" . formatter::toTex($this->illustration) . "}" . PHP_EOL; $tex .= "\\newcommand{\\" . getTexCommandName($this->getTitle()) . "ImplementationArchitecture}{" . formatter::toTex($this->architecture) . "}" . PHP_EOL; $tex .= "\\newcommand{\\" . getTexCommandName($this->getTitle()) . "ImplementationUsage}{" . formatter::toTex($this->usage) . "}" . PHP_EOL; $tex .= "\\newcommand{\\" . getTexCommandName($this->getTitle()) . "ImplementationIssues}{" . formatter::toTex($this->issues) . "}" . PHP_EOL; $ftxt = ""; foreach ($this->features as $f) { $ftxt .= "* [[101feature:" . $f . "]]" . PHP_EOL; } $tex .= "\\newcommand{\\" . getTexCommandName($this->getTitle()) . "ImplementationFeatures}{" . formatter::toTex(formatter::nestedList($ftxt)) . "}" . PHP_EOL; $tex = formatter::sourceLinks($this->getTitle(), $tex); return $tex; }