request("$url[path]$url[query]"); $title = ''; if ($response->getStatusCode()->value == 20) { ob_start(); $mime = explode(';', $response->getMeta())[0]; if (strpos($mime, 'text/gemini') === 0) { $parser = new Gemtext($response->getBody()); $lines = $parser->parse(); $wasListItem = false; $currentListItems = []; foreach ($lines as $line) { if ($wasListItem && $line['type'] !== 'listitem') { echo ""; $wasListItem = false; $currentListItems = []; } if ($line['type'] === 'preformatted_on') { echo "
$line[alt]
";
      }
      else if ($line['type'] === 'preformatted') {
        echo htmlentities($line['raw']);
      }
      else if ($line['type'] === 'preformatted_off') {
        echo "
"; } else if ($line['type'] === 'heading') { if (empty($title)) { $title = $line['text']; } echo "$line[text]"; } else if ($line['type'] === 'listitem') { $currentListItems[] = $line; $wasListItem = true; } else if ($line['type'] === 'quote') { echo "
$line[text]
"; } else if ($line['type'] === 'link') { $line['link'] = str_replace(["gemini://$geminiHost", $geminiHost], "https://$geminiHost", $line['link']); $line['text'] = $line['text'] ?: $line['link']; echo "$line[text]"; } else if ($line['type'] === 'text') { echo "

$line[text]

"; } } } else if (strpos($mime, 'text') === 0) { echo $response->getBody(); } else if (strpos($mime, 'image') === 0) { $src = "data:{$mime};base64," . base64_encode($response->getBody()); ?> getBody()); ?> getBody()); ?> getHeader(); echo $response->getHeader(); } echo "
"; echo "Original document at gemini://$geminiHost$url[path]$url[query]"; $content = ob_get_clean(); ?> <?php echo $title; ?>