From 5ea787cb0f5be84f5761600805be91bff68440dd Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 1 Aug 2024 18:10:05 +0300 Subject: [PATCH] implement link prefix indicators --- src/Interface/Model/Gtk/Pango/Markup.php | 3 +++ src/Model/Gtk/Pango/Markup/Gemtext.php | 29 ++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Interface/Model/Gtk/Pango/Markup.php b/src/Interface/Model/Gtk/Pango/Markup.php index 32068bd0..ceb07e97 100644 --- a/src/Interface/Model/Gtk/Pango/Markup.php +++ b/src/Interface/Model/Gtk/Pango/Markup.php @@ -22,6 +22,9 @@ interface Markup public const TAG_QUOTE = '%s'; public const TAG_TEXT = '%s'; + public const LINK_PREFIX_GEMINI = '⇒'; + public const LINK_PREFIX_DEFAULT = '⇗'; + public const WRAP_BREAK = PHP_EOL; public const WRAP_WIDTH = 320; // px diff --git a/src/Model/Gtk/Pango/Markup/Gemtext.php b/src/Model/Gtk/Pango/Markup/Gemtext.php index cbdf9103..786ba4db 100644 --- a/src/Model/Gtk/Pango/Markup/Gemtext.php +++ b/src/Model/Gtk/Pango/Markup/Gemtext.php @@ -116,14 +116,21 @@ class Gemtext extends \Yggverse\Yoda\Abstract\Model\Gtk\Pango\Markup else { + $prefix = self::LINK_PREFIX_DEFAULT; + $line[] = self::link( self::_url( $entity->getAddress(), - $request + $request, + $prefix ), $entity->getAddress(), - $entity->getAlt() ? $entity->getAlt() - : $entity->getAddress() // @TODO date + sprintf( + '%s %s', + $prefix, + $entity->getAlt() ? $entity->getAlt() + : $entity->getAddress() // @TODO date + ) ); } @@ -200,7 +207,8 @@ class Gemtext extends \Yggverse\Yoda\Abstract\Model\Gtk\Pango\Markup private static function _url( string $link, - string $base + string $base, + string &$prefix = self::LINK_PREFIX_DEFAULT ): ?string { $address = new Address( @@ -216,6 +224,19 @@ class Gemtext extends \Yggverse\Yoda\Abstract\Model\Gtk\Pango\Markup ); } + switch ($address->getScheme()) + { + case 'gemini': + + $prefix = self::LINK_PREFIX_GEMINI; + + break; + + default: + + $prefix = self::LINK_PREFIX_DEFAULT; + } + return $address->get(); } } \ No newline at end of file