Remove full head content in HTML to text converter
When extracting text from HTML part all the content between opening and closing tag should be removed
This commit is contained in:
parent
426bf9640a
commit
9e6baee9f3
@ -74,6 +74,6 @@ final class BodyRenderer implements BodyRendererInterface
|
|||||||
return $this->converter->convert($html);
|
return $this->converter->convert($html);
|
||||||
}
|
}
|
||||||
|
|
||||||
return strip_tags(preg_replace('{<(head|style)\b.*?</\1>}i', '', $html));
|
return strip_tags(preg_replace('{<(head|style)\b.*?</\1>}is', '', $html));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,23 @@ class BodyRendererTest extends TestCase
|
|||||||
$this->assertEquals(str_replace('=', '=3D', $html), $body->getParts()[1]->bodyToString());
|
$this->assertEquals(str_replace('=', '=3D', $html), $body->getParts()[1]->bodyToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRenderMultiLineHtmlOnly()
|
||||||
|
{
|
||||||
|
$html = <<<HTML
|
||||||
|
<head>
|
||||||
|
<style type="text/css">
|
||||||
|
css
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<b>HTML</b>
|
||||||
|
HTML;
|
||||||
|
$email = $this->prepareEmail(null, $html);
|
||||||
|
$body = $email->getBody();
|
||||||
|
$this->assertInstanceOf(AlternativePart::class, $body);
|
||||||
|
$this->assertEquals('HTML', str_replace(["\r", "\n"], '', $body->getParts()[0]->bodyToString()));
|
||||||
|
$this->assertEquals(str_replace(['=', "\n"], ['=3D', "\r\n"], $html), $body->getParts()[1]->bodyToString());
|
||||||
|
}
|
||||||
|
|
||||||
public function testRenderHtmlOnlyWithTextSet()
|
public function testRenderHtmlOnlyWithTextSet()
|
||||||
{
|
{
|
||||||
$email = $this->prepareEmail(null, '<b>HTML</b>');
|
$email = $this->prepareEmail(null, '<b>HTML</b>');
|
||||||
|
Reference in New Issue
Block a user