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

Void elements are no longer closed when using xhtml #161

Open
Stadly opened this issue Sep 21, 2016 · 7 comments
Open

Void elements are no longer closed when using xhtml #161

Stadly opened this issue Sep 21, 2016 · 7 comments

Comments

@Stadly
Copy link
Contributor

Stadly commented Sep 21, 2016

With version 2.2.0, void elements are no longer closed when using xhtml doctype.

The following document

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Title</title>
   </head>
   <body>
      <div>Message</div>
      <img src="foo.jpg" alt="bar" />
      <br />
      <hr />
   </body>
</html>

Will be converted into this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Title</title>
</head>
<body>
      <div>Message</div>
      <img src="foo.jpg" alt="bar">
      <br>
      <hr>
   </body>
</html>

Notice that the void elements (meta, img, br, hr) are not closed according to the xhtml standard. The / at the end of the elements are removed, even though the doctype is xhtml.

@zmip
Copy link

zmip commented May 3, 2020

Opened in 2016, no response? Where are people using this CSS inliner for, other than email? So this is a serious matter, because despite it's 2020 the safest, most used DOCTYPE is still XHTML 1.0 Transitional which requires slashes on self-closing (void) tags. Anyone know of an alternative CSS inliner that does respect these tags, allowing for email templates that actually validate?

@barryvdh
Copy link
Contributor

barryvdh commented May 3, 2020

Did you try submitting a PR?

@barryvdh
Copy link
Contributor

barryvdh commented May 3, 2020

Was this not fixed with #154 ?

@zmip
Copy link

zmip commented May 4, 2020

@barryvdh I did not submit a PR because... I don't have a fix ;-)
I cannot quite follow what happens at #154, because I hope the proposed hack was not implemented in the actual code. Will have to go through the code to see where this is happening. But no, it doesn't seem fixed in v2.2.2, but I'll investigate further...

@kvush
Copy link

kvush commented Apr 6, 2022

@zmip @barryvdh Have any updates? I faced with same problem.

@zmip
Copy link

zmip commented Apr 6, 2022

I think I went with Pelago/Emogrifier, but looking at the code, it seems I'm also post-processing br, meta and img tags to make them self-closing.

$emogrifier = new \Pelago\Emogrifier($html, $css);
$output = str_replace( ['<br>', 'src="/'], ['<br />', 'src="'.WEB_HOST.'/' ], $this->minify( $emogrifier->emogrify() ) );
$output = preg_replace( '/(<img.*?)>/', '\1 />', $output );
$output = preg_replace( '/(<meta.*?)>/', '\1 />', $output );

@kvush
Copy link

kvush commented Apr 10, 2022

@zmip thanks for response. Yeah look like post-processing is only way for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants