From aecaeaa7a282464f6121f09820fe8f91194db92f Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 12 Apr 2024 07:55:32 +0300 Subject: [PATCH] delegate pango formatter to yggverse/gemini library --- src/Entity/Tab/Page.php | 75 ++--------------------------------------- 1 file changed, 2 insertions(+), 73 deletions(-) diff --git a/src/Entity/Tab/Page.php b/src/Entity/Tab/Page.php index 81921f97..1f8823bc 100644 --- a/src/Entity/Tab/Page.php +++ b/src/Entity/Tab/Page.php @@ -418,7 +418,7 @@ class Page ); $this->content->set_markup( - $this->_gemtext( + \Yggverse\Gemini\Pango::fromGemtext( $response->getBody() ) ); @@ -482,7 +482,7 @@ class Page } $this->content->set_markup( - $this->_gemtext( + \Yggverse\Gemini\Pango::fromGemtext( $data ) ); @@ -501,75 +501,4 @@ class Page // @TODO update tab title } } - - private function _gemtext( - string $gemtext - ): string - { - // Format body - $body = new \Yggverse\Gemini\Gemtext\Body( - $gemtext - ); - - $lines = $body->getLines(); - - $escaped = []; - - /// Format H1 - foreach ($body->getH1() as $index => $h1) - { - $lines[$index] = sprintf( - '%s', - htmlentities( - $h1 - ) - ); - - $escaped[] = $index; - } - - /// Format H2 - foreach ($body->getH2() as $index => $h2) - { - $lines[$index] = sprintf( - '%s', - htmlentities( - $h2 - ) - ); - - $escaped[] = $index; - } - - /// Format H3 - foreach ($body->getH3() as $index => $h3) - { - $lines[$index] = sprintf( - '%s', - htmlentities( - $h3 - ) - ); - - $escaped[] = $index; - } - - /// Escape entities - foreach ($lines as $index => $line) - { - if (!in_array($index, $escaped)) - { - $lines[$index] = htmlentities( - $line - ); - } - } - - // @TODO links, code, escape entities - - return implode( - PHP_EOL, - $lines - ); - } } \ No newline at end of file