diff --git a/lib-htmgem.php b/lib-htmgem.php index a5635fa..96dd97c 100644 --- a/lib-htmgem.php +++ b/lib-htmgem.php @@ -107,50 +107,49 @@ class GemtextTranslate_gemtext { } protected function translate() { - ob_start(); + $output = ""; foreach ($this->parsedGemtext as $node) { $mode = $node["mode"]; switch($mode) { case "": - echo $node["text"]."\n"; + $output .= $node["text"]."\n"; break; case "*": foreach ($node["texts"] as $text) { - echo "* $text\n"; + $output .= "* $text\n"; } break; case "```": - print("```\n"); + $output .= "```\n"; foreach ($node["texts"] as $text) { - echo "$text\n"; + $output .= "$text\n"; } - print("```\n"); + $output .= "```\n"; break; case ">": foreach ($node["texts"] as $text) { - echo "> $text\n"; + $output .= "> $text\n"; } break; case "=>": $linkText = $node["text"]; if (!empty($linkText)) $linkText = " $linkText"; - print("=> ".$node["link"].$linkText."\n"); + $output .= "=> ".$node["link"].$linkText."\n"; break; case "#": case "##": case "###": - print("$mode ".$node["title"]."\n"); + $output .= "$mode ".$node["title"]."\n"; break; case "^^^": - print("^^^\n"); + $output .= "^^^\n"; break; default: die("Unknown mode: '{$node["mode"]}'\n"); } } - $this->translatedGemtext = ob_get_contents(); - ob_end_clean(); + $this->translatedGemtext = $output; } public function __toString() { @@ -246,7 +245,7 @@ class GemtextTranslate_html { } public function translate($textDecoration=true) { - ob_start(); + $output = ""; foreach ($this->parsedGemtext as $node) { $mode = $node["mode"]; switch($mode) { @@ -254,27 +253,27 @@ class GemtextTranslate_html { $text = $node["text"]; self::htmlPrepare($text); if ($textDecoration) self::addTextDecoration($text); - echo "

$text

\n"; + $output .= "

$text

\n"; break; case "*": - echo "\n"; break; case "```": $text = implode("\n", $node["texts"]); self::htmlPrepare($text); - echo "
\n$text\n
\n"; + $output .= "
\n$text\n
\n"; break; case ">": $text = implode("\n", $node["texts"]); self::htmlPrepare($text); if ($textDecoration) self::addTextDecoration($text); - echo "
\n$text\n
\n"; + $output .= "
\n$text\n
\n"; break; case "=>": $link = $node["link"]; @@ -289,23 +288,23 @@ class GemtextTranslate_html { preg_match("/^([^:]+):/", $link, $matches); $protocol = @$matches[1]; if (empty($protocol)) $protocol = "local"; - echo "

$linkText

\n"; + $output .= "

$linkText

\n"; break; case "#": $title = $node["title"]; self::htmlPrepare($title); if (empty($this->pageTitle)) $this->pageTitle = $title; - echo "

$title

\n"; + $output .= "

$title

\n"; break; case "##": $title = $node["title"]; self::htmlPrepare($title); - echo "

$title

\n"; + $output .= "

$title

\n"; break; case "###": $title = $node["title"]; self::htmlPrepare($title); - echo "

$title

\n"; + $output .= "

$title

\n"; break; case "^^^": $textDecoration = !$textDecoration; @@ -315,8 +314,7 @@ class GemtextTranslate_html { } } - $this->translatedGemtext = ob_get_contents(); - ob_end_clean(); + $this->translatedGemtext = $output; } function getFullHtml() { @@ -324,7 +322,7 @@ class GemtextTranslate_html { $css = array("/htmgem/css/htmgem.css"); else $css = $this->cssList; - echo << @@ -332,14 +330,16 @@ class GemtextTranslate_html { EOL; foreach ($css as $c) { - echo "\n"; + $output .= "\n"; } - echo << \n EOL; - echo $this->translatedGemtext; - echo "\n\n"; + $output .= $this->translatedGemtext; + $output .= "\n\n"; + + echo $output; } public function __toString() {