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

Option for disabling "pretty printing" of html part #345

Open
AnrichVS opened this issue May 10, 2017 · 3 comments
Open

Option for disabling "pretty printing" of html part #345

AnrichVS opened this issue May 10, 2017 · 3 comments

Comments

@AnrichVS
Copy link

AnrichVS commented May 10, 2017

Some of the mails I send contain user submitted content that was created by Quill editor. Quill editor relies on the white-space: pre-wrap; CSS property to preserve tabs and multiple spaces, see this.

The to_inline_css method(premailer-1.10.3/lib/premailer/adapter/nokogiri.rb:12) causes "pretty printing" of the html that is returned, meaning that newlines are created. Due to white-space: pre-wrap; this causes extra whitespace in the mail. The specific line that causes the "pretty printing" is premailer-1.10.3/lib/premailer/adapter/nokogiri.rb:224. This line does: doc = ::Nokogiri::HTML(thing, nil, @options[:input_encoding] || default_encoding) { |c| c.recover }, NokogiriL::HTML uses DEFAULT_HTML save options, which includes FORMAT. See this.

To overcome this, this can be done:
doc = ::Nokogiri::HTML(thing, nil, @options[:input_encoding] || default_encoding, Nokogiri::XML::Node::SaveOptions::DEFAULT_HTML ^ Nokogiri::XML::Node::SaveOptions::FORMAT) { |c| c.recover }

Preferably that would be a option, which can then be passed through via @options.

I plan on making a pull request for this soon, creating this issue to ensure that I'm not missing something. I've perused all the current options, and it doesn't seem like there's any other way to overcome this. I guess one can create an interceptor that strips new lines before sending the mail, but it feels like a dirty workaround.

@akzhan
Copy link
Member

akzhan commented May 10, 2017

You should create specs on all of supported adapters (:nokogiri, :nokogiri_fast, :nokogumbo).

@AnrichVS
Copy link
Author

Unfortunately I haven't had time to work on this, but I will create specs for all those adaptors once I do complete implementation.

Note to self: the Nokogiri save options should not be passed at ::Nokogiri::HTML() but rather to the .to_html() method, as in:
@processed_doc.to_html(:encoding => @options[:output_encoding], save_with: @options[:nokogiri_html_options])

@akzhan
Copy link
Member

akzhan commented May 17, 2017

It's simple as

[:nokogiri, :nokogiri_fast, :nokogumbo].each do |adapter|
  # instantiate
end

Specs like that are common.

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

2 participants