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

Save as html instead of xml. Fixes self-closing tags and utf-8 encoding. #154

Merged
merged 1 commit into from
Sep 5, 2016
Merged

Conversation

josh18
Copy link
Contributor

@josh18 josh18 commented Jul 26, 2016

This solves the issues with self-closing tags (<br> going to <br></br>) and assists with utf-8 encoding.

@techi602 I think this should solve all the utf-8 encoding issues?

$document = new \DOMDocument('1.0', 'UTF-8');
$internalErrors = libxml_use_internal_errors(true);
$document->loadHTML($html);
$document->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why converting the encoding here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof otherwise the utf-8 encoding doesn't work correctly for some reason.

Example

@techi602
Copy link
Contributor

techi602 commented Aug 18, 2016

This solves the issues with self-closing tags (<br> going to <br></br>)
and assists with utf-8 encoding.
@josh18
Copy link
Contributor Author

josh18 commented Aug 30, 2016

@techi602 Good point, I've added in both of your tests (they both passed).

@techi602
Copy link
Contributor

techi602 commented Sep 1, 2016

👍

@FilipNovy
Copy link

@tijsverkoyen
Please, please merge this & release new version ASAP.
This is nifty component but this
makes problems in emails.
Thank you!!

@c960657
Copy link
Contributor

c960657 commented Sep 21, 2016

@josh18 Why is the HTML5 doctype converted to lowercase? <!doctype html> and <!DOCTYPE html> equally valid, and I don't know of any compatibility problems with either.

See also http://stackoverflow.com/questions/7020961/uppercase-or-lowercase-doctype

@josh18
Copy link
Contributor Author

josh18 commented Sep 22, 2016

You are right, either is fine. If I remember correctly DOMDocument always converts it to uppercase so I converted it to lowercase so that it matches the user put in lowercase. Of course this means it won't match if the user starts with uppercase but it seems like lowercase is more of the "standard" for html5, for example HTML5Boilerplate.

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

Successfully merging this pull request may close these issues.

6 participants