Removes ob_* functions

This commit is contained in:
Christophe HENRY 2021-03-19 17:39:42 +01:00
parent 66720ed63f
commit 0e508a7d57
1 changed files with 30 additions and 30 deletions

View File

@ -107,50 +107,49 @@ class GemtextTranslate_gemtext {
} }
protected function translate() { protected function translate() {
ob_start(); $output = "";
foreach ($this->parsedGemtext as $node) { foreach ($this->parsedGemtext as $node) {
$mode = $node["mode"]; $mode = $node["mode"];
switch($mode) { switch($mode) {
case "": case "":
echo $node["text"]."\n"; $output .= $node["text"]."\n";
break; break;
case "*": case "*":
foreach ($node["texts"] as $text) { foreach ($node["texts"] as $text) {
echo "* $text\n"; $output .= "* $text\n";
} }
break; break;
case "```": case "```":
print("```\n"); $output .= "```\n";
foreach ($node["texts"] as $text) { foreach ($node["texts"] as $text) {
echo "$text\n"; $output .= "$text\n";
} }
print("```\n"); $output .= "```\n";
break; break;
case ">": case ">":
foreach ($node["texts"] as $text) { foreach ($node["texts"] as $text) {
echo "> $text\n"; $output .= "> $text\n";
} }
break; break;
case "=>": case "=>":
$linkText = $node["text"]; $linkText = $node["text"];
if (!empty($linkText)) $linkText = " $linkText"; if (!empty($linkText)) $linkText = " $linkText";
print("=> ".$node["link"].$linkText."\n"); $output .= "=> ".$node["link"].$linkText."\n";
break; break;
case "#": case "#":
case "##": case "##":
case "###": case "###":
print("$mode ".$node["title"]."\n"); $output .= "$mode ".$node["title"]."\n";
break; break;
case "^^^": case "^^^":
print("^^^\n"); $output .= "^^^\n";
break; break;
default: default:
die("Unknown mode: '{$node["mode"]}'\n"); die("Unknown mode: '{$node["mode"]}'\n");
} }
} }
$this->translatedGemtext = ob_get_contents(); $this->translatedGemtext = $output;
ob_end_clean();
} }
public function __toString() { public function __toString() {
@ -246,7 +245,7 @@ class GemtextTranslate_html {
} }
public function translate($textDecoration=true) { public function translate($textDecoration=true) {
ob_start(); $output = "";
foreach ($this->parsedGemtext as $node) { foreach ($this->parsedGemtext as $node) {
$mode = $node["mode"]; $mode = $node["mode"];
switch($mode) { switch($mode) {
@ -254,27 +253,27 @@ class GemtextTranslate_html {
$text = $node["text"]; $text = $node["text"];
self::htmlPrepare($text); self::htmlPrepare($text);
if ($textDecoration) self::addTextDecoration($text); if ($textDecoration) self::addTextDecoration($text);
echo "<p>$text</p>\n"; $output .= "<p>$text</p>\n";
break; break;
case "*": case "*":
echo "<ul>\n"; $output .= "<ul>\n";
foreach ($node["texts"] as $text) { foreach ($node["texts"] as $text) {
self::htmlPrepare($text); self::htmlPrepare($text);
if ($textDecoration) self::addTextDecoration($text); if ($textDecoration) self::addTextDecoration($text);
print("<li>$text\n"); $output .= "<li>$text\n";
} }
echo "</ul>\n"; $output .= "</ul>\n";
break; break;
case "```": case "```":
$text = implode("\n", $node["texts"]); $text = implode("\n", $node["texts"]);
self::htmlPrepare($text); self::htmlPrepare($text);
echo "<pre>\n$text\n</pre>\n"; $output .= "<pre>\n$text\n</pre>\n";
break; break;
case ">": case ">":
$text = implode("\n", $node["texts"]); $text = implode("\n", $node["texts"]);
self::htmlPrepare($text); self::htmlPrepare($text);
if ($textDecoration) self::addTextDecoration($text); if ($textDecoration) self::addTextDecoration($text);
echo "<blockquote>\n$text\n</blockquote>\n"; $output .= "<blockquote>\n$text\n</blockquote>\n";
break; break;
case "=>": case "=>":
$link = $node["link"]; $link = $node["link"];
@ -289,23 +288,23 @@ class GemtextTranslate_html {
preg_match("/^([^:]+):/", $link, $matches); preg_match("/^([^:]+):/", $link, $matches);
$protocol = @$matches[1]; $protocol = @$matches[1];
if (empty($protocol)) $protocol = "local"; if (empty($protocol)) $protocol = "local";
echo "<p><a class='$protocol' href='$link'>$linkText</a></p>\n"; $output .= "<p><a class='$protocol' href='$link'>$linkText</a></p>\n";
break; break;
case "#": case "#":
$title = $node["title"]; $title = $node["title"];
self::htmlPrepare($title); self::htmlPrepare($title);
if (empty($this->pageTitle)) $this->pageTitle = $title; if (empty($this->pageTitle)) $this->pageTitle = $title;
echo "<h1>$title</h1>\n"; $output .= "<h1>$title</h1>\n";
break; break;
case "##": case "##":
$title = $node["title"]; $title = $node["title"];
self::htmlPrepare($title); self::htmlPrepare($title);
echo "<h2>$title</h2>\n"; $output .= "<h2>$title</h2>\n";
break; break;
case "###": case "###":
$title = $node["title"]; $title = $node["title"];
self::htmlPrepare($title); self::htmlPrepare($title);
echo "<h3>$title</h3>\n"; $output .= "<h3>$title</h3>\n";
break; break;
case "^^^": case "^^^":
$textDecoration = !$textDecoration; $textDecoration = !$textDecoration;
@ -315,8 +314,7 @@ class GemtextTranslate_html {
} }
} }
$this->translatedGemtext = ob_get_contents(); $this->translatedGemtext = $output;
ob_end_clean();
} }
function getFullHtml() { function getFullHtml() {
@ -324,7 +322,7 @@ class GemtextTranslate_html {
$css = array("/htmgem/css/htmgem.css"); $css = array("/htmgem/css/htmgem.css");
else else
$css = $this->cssList; $css = $this->cssList;
echo <<<EOL $output = <<<EOL
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@ -332,14 +330,16 @@ class GemtextTranslate_html {
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
EOL; EOL;
foreach ($css as $c) { foreach ($css as $c) {
echo "<link type='text/css' rel='StyleSheet' href='$c'>\n"; $output .= "<link type='text/css' rel='StyleSheet' href='$c'>\n";
} }
echo <<<EOL $output .= <<<EOL
</head> </head>
<body>\n <body>\n
EOL; EOL;
echo $this->translatedGemtext; $output .= $this->translatedGemtext;
echo "</body>\n</html>\n"; $output .= "</body>\n</html>\n";
echo $output;
} }
public function __toString() { public function __toString() {