Replaced embeds with images in exports

This commit is contained in:
Dan Brown 2022-05-24 18:05:47 +01:00
parent 05f8034439
commit bf0ba9f756
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 6 additions and 3 deletions

View File

@ -215,9 +215,12 @@ class ExportFormatter
*/
protected function containHtml(string $htmlContent): string
{
// Replace embed tags with images
$htmlContent = preg_replace("/<embed (.*?)>/i", '<img $1>', $htmlContent);
// Replace image & embed src attributes with base64 encoded data strings
$imageTagsOutput = [];
preg_match_all("/<(?:img|embed) .*?src=['\"](.*?)['\"].*?>/i", $htmlContent, $imageTagsOutput);
preg_match_all("/<img .*?src=['\"](.*?)['\"].*?>/i", $htmlContent, $imageTagsOutput);
if (isset($imageTagsOutput[0]) && count($imageTagsOutput[0]) > 0) {
foreach ($imageTagsOutput[0] as $index => $imgMatch) {
$oldImgTagString = $imgMatch;

View File

@ -258,7 +258,7 @@ class ExportTest extends TestCase
unlink($testFilePath);
}
public function test_page_export_contained_html_embed_element_srcs_are_inlined()
public function test_page_export_contained_html_embed_elements_are_converted_to_images_with_srcs_inlined()
{
$page = Page::query()->first();
$page->html = '<embed src="http://localhost/uploads/images/gallery/svg_test.svg"/>';
@ -273,7 +273,7 @@ class ExportTest extends TestCase
$storageDisk->delete('uploads/images/gallery/svg_test.svg');
$resp->assertDontSee('http://localhost/uploads/images/gallery/svg_test.svg', false);
$resp->assertSee('<embed src="data:image/svg+xml;base64,PHN2Zz5nb29kPC9zdmc+">', false);
$resp->assertSee('<img src="data:image/svg+xml;base64,PHN2Zz5nb29kPC9zdmc+">', false);
}
public function test_exports_removes_scripts_from_custom_head()