-
-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Message::buildText(): Trim each text line. #84
Conversation
@@ -382,6 +382,7 @@ protected function buildText(string $html): string | |||
]); | |||
$text = Nette\Utils\Html::htmlToText($html); | |||
$text = Strings::replace($text, '#[ \t]+#', ' '); | |||
$text = implode("\n", array_map(static fn(string $line): string => trim($line), explode("\n", str_replace(["\r\n", "\r"], "\n", $text)))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static fn(string $line): string => trim($line)
can be simply 'trim'
, or can't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has one difference - PHP calls function internally, so weak typing is used instead of strict types
https://chat.stackoverflow.com/transcript/message/40320863#40320863
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, should I change it or will we let it go?
Co-authored-by: David Grudl <[email protected]>
In some cases, when converting HTML to text, blanks are left at the beginning and end of lines. This modification removes these unnecessary characters (saves storage when serializing messages and unifies formatting).
Thanks!