From dc581d6071c6a9b9939fa6d04b646c6e1478b0a9 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 23 Jun 2024 20:31:01 +0300 Subject: [PATCH] implement link parser class --- src/Parser/Line/Link.php | 97 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/Parser/Line/Link.php diff --git a/src/Parser/Line/Link.php b/src/Parser/Line/Link.php new file mode 100644 index 0000000..8d1ae7c --- /dev/null +++ b/src/Parser/Line/Link.php @@ -0,0 +1,97 @@ +isEscaped()) + { + return false; + } + + return (bool) preg_match( + '/^=>\s*(?
[^\s]+)(\s(?\d{4}-\d{2}-\d{2}))?(\s(?.+))?$/m', + $line->getData(), + $matches + ); + } + + public static function getAddress( + \Yggverse\Gemtext\Entity\Line $line + ): ?string + { + $matches = []; + + if (self::match($line, $matches)) + { + if (isset($matches['address'])) + { + $address = trim( + $matches['address'] + ); + + if ($address) + { + return $address; + } + } + } + + return null; + } + + public static function getDate( + \Yggverse\Gemtext\Entity\Line $line + ): ?string + { + $matches = []; + + if (self::match($line, $matches)) + { + if (isset($matches['date'])) + { + $date = trim( + $matches['date'] + ); + + if ($date) + { + return $date; + } + } + } + + return null; + } + + public static function getAlt( + \Yggverse\Gemtext\Entity\Line $line + ): ?string + { + $matches = []; + + if (self::match($line, $matches)) + { + if (isset($matches['alt'])) + { + $alt = trim( + $matches['alt'] + ); + + if ($alt) + { + return $alt; + } + } + } + + return null; + } +} \ No newline at end of file