Skip to content
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

Fix void elements that libxml2 does not know #142

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Combine two str_replace() into one
  • Loading branch information
krokodok committed Sep 30, 2024
commit 045fb0c7659dc111be33b583db4b64ef56c5a138
15 changes: 5 additions & 10 deletions inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
'<?xml encoding="utf-8"?>',
'<preserveselfclosingtags>',
'</preserveselfclosingtags>',
'</embed>',
'</source>',
'</track>',
'</wbr>',
],
'',
(string) $document->saveHTML()
Expand All @@ -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 = [
'</embed>',
'</source>',
'</track>',
'</wbr>',
];
$content = str_replace( $stray_end_tags, '', $content );

// phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase

if ( $lightboxes > 0 && ! wp_script_is( 'required-tobii-integration' ) ) {
Expand Down
Loading