You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reason for that is in \voku\Html2Text\Html2Text::pregCallback. $matches['element'] is initially converted to lowercase with
$element = \strtolower($matches['element']);
but the lowercase version is not used in the switch statement or to match headings:
protectedfunction pregCallback(array$matches): string
{
// init$element = \strtolower($matches['element']);
switch ($matches['element']) { // Case sensitivecase'p':
// Replace newlines with spaces.$para = \str_replace("\n", '', $matches['value']);
// Add trailing newlines for this paragraph.return"\n\n" . $para . "\n\n";
...
...
}
// h1 - h6if (\preg_match('/h[123456]/', $matches['element'])) { // Case sensitivereturn$this->convertElement($matches['value'], $matches['element']);
}
I don't understand why pregCallback returns an empty string as last line.
Shouldn't the code always know how to handle the $matches['element'] that ends up in pregCallback?
Wouldn't it be better to throw an exception in case there is no handling available for a match $matches['element']
or return $matches['value'] ?? ''?
The text was updated successfully, but these errors were encountered:
prints nothing while
prints
Test string
as expected.The reason for that is in
\voku\Html2Text\Html2Text::pregCallback
.$matches['element']
is initially converted to lowercase withbut the lowercase version is not used in the switch statement or to match headings:
I don't understand why
pregCallback
returns an empty string as last line.Shouldn't the code always know how to handle the
$matches['element']
that ends up inpregCallback
?Wouldn't it be better to throw an exception in case there is no handling available for a match
$matches['element']
or return
$matches['value'] ?? ''
?The text was updated successfully, but these errors were encountered: