diff --git a/src/Abstract/Model/Gtk/Pango/Markup.php b/src/Abstract/Model/Gtk/Pango/Markup.php new file mode 100644 index 00000000..bdc1e505 --- /dev/null +++ b/src/Abstract/Model/Gtk/Pango/Markup.php @@ -0,0 +1,134 @@ +%s', + htmlspecialchars( + $value + ) + ); + } + + public static function h1( + string $value + ): string + { + return sprintf( + '%s', + htmlspecialchars( + $value + ) + ); + } + + public static function h2( + string $value + ): string + { + return sprintf( + '%s', + htmlspecialchars( + $value + ) + ); + } + + public static function h3( + string $value + ): string + { + return sprintf( + '%s', + htmlspecialchars( + $value + ) + ); + } + + public static function link( + string $href, + string $title, + string $value + ): string + { + return sprintf( + '%s', + htmlspecialchars( + $href + ), + htmlspecialchars( + $title + ), + htmlspecialchars( + $value + ) + ); + } + + public static function list( + string $value + ): string + { + return sprintf( + '* %s', // @TODO + htmlspecialchars( + $value + ) + ); + } + + public static function quote( + string $value + ): string + { + return sprintf( + '%s', + htmlspecialchars( + $value + ) + ); + } + + public static function text( + string $value + ): string + { + return htmlspecialchars( + $value + ); + } + + public static function pre( + string $value + ): string + { + return htmlspecialchars( + $value + ); + } + + public static function tag( + string $const, + bool $close + ): string + { + if (in_array($const, [self::TAG_CODE])) + { + return sprintf( + $close ? '' : '<%s>', + $const + ); + } + + throw new Exception; + } +} \ No newline at end of file diff --git a/src/Entity/Browser/Container/Page/Content/Gemtext.php b/src/Entity/Browser/Container/Page/Content/Gemtext.php index f3ebbbf3..676de88e 100644 --- a/src/Entity/Browser/Container/Page/Content/Gemtext.php +++ b/src/Entity/Browser/Container/Page/Content/Gemtext.php @@ -10,7 +10,7 @@ use \GdkEvent; use \GtkLabel; use \Pango; -use \Yggverse\Yoda\Abstract\Entity\Browser\Container\Page\Content\Markup; +use \Yggverse\Yoda\Model\Gtk\Pango\Markup; use \Yggverse\Gemtext\Document; use \Yggverse\Gemtext\Entity\Code; @@ -20,10 +20,9 @@ use \Yggverse\Gemtext\Entity\Listing; use \Yggverse\Gemtext\Entity\Quote; use \Yggverse\Gemtext\Entity\Text; -use \Yggverse\Gemtext\Parser\Link as LinkParser; +# use \Yggverse\Gemtext\Parser\Link as LinkParser; - -class Gemtext extends Markup +class Gemtext extends \Yggverse\Yoda\Abstract\Entity\Browser\Container\Page\Content\Markup { public function set( string $source, @@ -45,17 +44,15 @@ class Gemtext extends Markup if ($entity->isInline()) { - $line[] = sprintf( - '%s', - htmlspecialchars( - $entity->getAlt() - ) + $line[] = Markup::code( + $entity->getAlt() ); } else { - $line[] = $preformatted ? '' : ''; + $line[] = $preformatted ? Markup::tag(Markup::TAG_CODE, true) + : Markup::tag(Markup::TAG_CODE, false); $preformatted = !($preformatted); // toggle } @@ -66,10 +63,8 @@ class Gemtext extends Markup if ($preformatted) { - $line[] = htmlspecialchars( - $this->_wrap( - $entity->toString() - ) + $line[] = Markup::pre( + $entity->toString() ); } @@ -79,13 +74,8 @@ class Gemtext extends Markup { case 1: // # - $line[] = sprintf( - '%s', - htmlspecialchars( - $this->_wrap( - $entity->getText() - ) - ) + $line[] = Markup::h1( + $entity->getText() ); // Find and return document title by first # tag @@ -98,26 +88,16 @@ class Gemtext extends Markup case 2: // ## - $line[] = sprintf( - '%s', - htmlspecialchars( - $this->_wrap( - $entity->getText() - ) - ) + $line[] = Markup::h2( + $entity->getText() ); break; case 3: // ### - $line[] = sprintf( - '%s', - htmlspecialchars( - $this->_wrap( - $entity->getText() - ) - ) + $line[] = Markup::h3( + $entity->getText() ); break; @@ -133,31 +113,20 @@ class Gemtext extends Markup if ($preformatted) { - $line[] = htmlspecialchars( - $this->_wrap( - $entity->toString() - ) + $line[] = Markup::pre( + $entity->toString() ); } else { - $line[] = sprintf( - '%s', - htmlspecialchars( - $this->_url( - $entity->getAddress() - ) - ), - htmlspecialchars( + $line[] = Markup::h3( + $this->_url( $entity->getAddress() ), - htmlspecialchars( - $this->_wrap( - $entity->getAlt() ? $entity->getAlt() - : $entity->getAddress() // @TODO date - ) - ) + $entity->getAddress(), + $entity->getAlt() ? $entity->getAlt() + : $entity->getAddress() // @TODO date ); } @@ -167,22 +136,15 @@ class Gemtext extends Markup if ($preformatted) { - $line[] = htmlspecialchars( - $this->_wrap( - $entity->toString() - ) + $line[] = Markup::pre( + $entity->toString() ); } else { - $line[] = sprintf( - '* %s', - htmlspecialchars( - $this->_wrap( - $entity->getItem() - ) - ) + $line[] = Markup::list( + $entity->getItem() ); } @@ -192,22 +154,15 @@ class Gemtext extends Markup if ($preformatted) { - $line[] = htmlspecialchars( - $this->_wrap( - $entity->toString() - ) + $line[] = Markup::pre( + $entity->toString() ); } else { - $line[] = sprintf( - '%s', - htmlspecialchars( - $this->_wrap( - $entity->getText() - ) - ) + $line[] = Markup::quote( + $entity->getText() ); } @@ -217,19 +172,15 @@ class Gemtext extends Markup if ($preformatted) { - $line[] = htmlspecialchars( - $this->_wrap( - $entity->toString() - ) + $line[] = Markup::pre( + $entity->toString() ); } else { - $line[] = htmlspecialchars( - $this->_wrap( - $entity->getData() - ) + $line[] = Markup::text( + $entity->getData() ); } @@ -327,13 +278,4 @@ class Gemtext extends Markup return false; } - - protected function _onSizeAllocate( - GtkLabel $label, - GdkEvent $event - ): bool - { - // @TODO - return false; - } } \ No newline at end of file diff --git a/src/Entity/Browser/Container/Page/Content/Plain.php b/src/Entity/Browser/Container/Page/Content/Plain.php index 4366a286..abed3023 100644 --- a/src/Entity/Browser/Container/Page/Content/Plain.php +++ b/src/Entity/Browser/Container/Page/Content/Plain.php @@ -7,30 +7,18 @@ namespace Yggverse\Yoda\Entity\Browser\Container\Page\Content; use \GdkEvent; use \GtkLabel; -use \Yggverse\Yoda\Abstract\Entity\Browser\Container\Page\Content\Markup; +use \Yggverse\Yoda\Model\Gtk\Pango\Markup; -class Plain extends Markup +class Plain extends \Yggverse\Yoda\Abstract\Entity\Browser\Container\Page\Content\Markup { public function set( string $source ): void { $this->gtk->set_markup( - sprintf( - '%s', - htmlspecialchars( - $this->_source = $source - ) + Markup::code( // @TODO + $this->_source = $source ) ); } - - protected function _onSizeAllocate( - GtkLabel $label, - GdkEvent $event - ): bool - { - // @TODO - return false; - } } \ No newline at end of file diff --git a/src/Interface/Model/Gtk/Pango/Markup.php b/src/Interface/Model/Gtk/Pango/Markup.php new file mode 100644 index 00000000..0be4e478 --- /dev/null +++ b/src/Interface/Model/Gtk/Pango/Markup.php @@ -0,0 +1,57 @@ +