Closed gkampjes closed 3 years ago
Thanks for the feedback!
Should I move the test cases to utm_params_test.rb
, click_test.rb
, or both? And should I also scrap fixtures/email.html
and inline the html in test mailer(s) instead?
Looks great, thanks @gkampjes! Pushing a new release now.
Changes
AhoyEmail::Processor
to use parse the email body as aNokogiri::HTML::Document
Context
As of v2.0, the processor uses
Nokogiri::HTML::DocumentFragment
to parse the email body, rather thanNokogiri::HTML::Document
.Despite what the semantics of
Mail::Message#body
implies, it actually returns the compete HTML document, including the<head>
.It appears that
Nokogiri::HTML::DocumentFragment#parse
strips any invalid nodes, essentially anything that's valid within a<body>
element. The main impact is that any emails relying on<style>
elements in the header will render without any CSS styling in Gmail. Additionally, thestyle=
attribute on the<body>
tag gets stripped off.Parsing a document fragment with
Nokogiri::HTML::Document
doesn't appear to have any negative impacts, it simply adds the required elements to create a valid HTML document. There is a possibility that automatically added doctype may cause some formatting issues, and if that's a concern, I can default the doctype to HTML5.Before/After behaviour
With a full HTML document
Parsing as a
Nokogiri::HTML::DocumentFragment
(current behaviour) mangles the HTML into this:Using
Nokogiri::HTML::Document
, the email correctly is processed into this:With a document fragment
Current behaviour (
Nokogiri::HTML::DocumentFragment
):Using
Nokogiri::HTML::Document
: