From 2cbdcbf25561d4c3aa538641549f31f6de602725 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 14 Apr 2024 07:50:59 +0300 Subject: [PATCH] add links support --- src/Pango.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Pango.php b/src/Pango.php index a3855db..97b7ad9 100644 --- a/src/Pango.php +++ b/src/Pango.php @@ -138,7 +138,39 @@ class Pango } } - // @TODO links + // Links + foreach ($body->getLinks() as $index => $line) + { + if (!isset($raw[$index])) + { + $link = new \Yggverse\Gemini\Gemtext\Link( + $line + ); + + if (!$address = $link->getAddress()) + { + continue; + } + + if (!$alt = $link->getAlt()) + { + if (!$alt = $link->getDate()) + { + $alt = $address; + } + } + + $lines[$index] = sprintf( + '%s', + $address, + self::escape( + $alt + ) + ); + + $escaped[] = $index; + } + } // Escape special chars for non escaped lines foreach ($body->getLines() as $index => $value)