From c24cfa662f011ba13651205825eee675fd6c0e2e Mon Sep 17 00:00:00 2001 From: krokodok Date: Tue, 3 Sep 2024 10:09:33 +0200 Subject: [PATCH 1/2] Fix void elements that libxml2 does not know --- inc/namespace.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/inc/namespace.php b/inc/namespace.php index 2c95fb2..e08c941 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -161,6 +161,15 @@ function enable_lightbox_for_images( string $content ): string { $content = $document_html; } + // Remove stray end tags of void elements libxml2 does not know. + $stray_end_tags = [ + '', + '', + '', + '', + ]; + $content = str_replace( $stray_end_tags, '', $content ); + // phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase if ( $lightboxes > 0 && ! wp_script_is( 'required-tobii-integration' ) ) { From 045fb0c7659dc111be33b583db4b64ef56c5a138 Mon Sep 17 00:00:00 2001 From: krokodok Date: Mon, 30 Sep 2024 15:44:35 +0200 Subject: [PATCH 2/2] Combine two `str_replace()` into one --- inc/namespace.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/inc/namespace.php b/inc/namespace.php index e08c941..b89a522 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -145,13 +145,17 @@ function enable_lightbox_for_images( string $content ): string { $link->setAttribute( 'data-group', $image_id ); } - // Strip the XML tag and placeholders as it's only used for the internal encoding. + // Strip XML tag, internal encoding placeholders and stray end tags of void elements unknown to libxml2. $document_html = trim( str_replace( [ '', '', '', + '', + '', + '', + '', ], '', (string) $document->saveHTML() @@ -161,15 +165,6 @@ function enable_lightbox_for_images( string $content ): string { $content = $document_html; } - // Remove stray end tags of void elements libxml2 does not know. - $stray_end_tags = [ - '', - '', - '', - '', - ]; - $content = str_replace( $stray_end_tags, '', $content ); - // phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase if ( $lightboxes > 0 && ! wp_script_is( 'required-tobii-integration' ) ) {