From 539dc97372b5c3482a06a79b7feb5a8bc573e566 Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 25 Jun 2024 03:22:08 +0300 Subject: [PATCH] format toString separators --- src/Entity/Code.php | 13 ++++++++++++- src/Entity/Header.php | 14 ++++++++++---- src/Entity/Link.php | 8 +++++--- src/Entity/Listing.php | 8 +++++++- src/Entity/Quote.php | 8 +++++++- 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/Entity/Code.php b/src/Entity/Code.php index 8494f79..240bbfd 100755 --- a/src/Entity/Code.php +++ b/src/Entity/Code.php @@ -58,6 +58,17 @@ class Code implements \Yggverse\Gemtext\Interface\Entity public function toString(): string { - return self::TAG . $this->_alt . ($this->_inline ? self::TAG : null); + return $this->_inline ? sprintf( + '%s%s%s', + self::TAG, + $this->_alt, + self::TAG + ) : trim( + sprintf( + '%s %s', + self::TAG, + $this->_alt + ) + ); } } \ No newline at end of file diff --git a/src/Entity/Header.php b/src/Entity/Header.php index bf37a8d..6025d8c 100755 --- a/src/Entity/Header.php +++ b/src/Entity/Header.php @@ -65,9 +65,15 @@ class Header implements \Yggverse\Gemtext\Interface\Entity public function toString(): string { - return str_repeat( - self::TAG, - $this->_level - ) . $this->_text; + return trim( + sprintf( + '%s %s', + str_repeat( + self::TAG, + $this->_level + ), + $this->_text + ) + ); } } \ No newline at end of file diff --git a/src/Entity/Link.php b/src/Entity/Link.php index 2b86554..2fab35e 100755 --- a/src/Entity/Link.php +++ b/src/Entity/Link.php @@ -116,9 +116,11 @@ class Link implements \Yggverse\Gemtext\Interface\Entity $parts[] = $alt; } - return implode( - ' ', - $parts + return trim( + implode( + ' ', + $parts + ) ); } } \ No newline at end of file diff --git a/src/Entity/Listing.php b/src/Entity/Listing.php index 0e9c26c..d7b27b0 100755 --- a/src/Entity/Listing.php +++ b/src/Entity/Listing.php @@ -39,6 +39,12 @@ class Listing implements \Yggverse\Gemtext\Interface\Entity public function toString(): string { - return self::TAG . ' ' . $this->_item; + return trim( + sprintf( + '%s %s', + self::TAG, + $this->_item + ) + ); } } \ No newline at end of file diff --git a/src/Entity/Quote.php b/src/Entity/Quote.php index df97d3c..407b7f3 100755 --- a/src/Entity/Quote.php +++ b/src/Entity/Quote.php @@ -39,6 +39,12 @@ class Quote implements \Yggverse\Gemtext\Interface\Entity public function toString(): string { - return self::TAG . ' ' . $this->_text; + return trim( + sprintf( + '%s %s', + self::TAG, + $this->_text + ) + ); } } \ No newline at end of file