Skip to content

Commit

Permalink
Merge pull request #181 from amclin/master
Browse files Browse the repository at this point in the history
Add support for HTML Entity encoding output when using Nokogiri
  • Loading branch information
akzhan committed Mar 11, 2014
2 parents 24d6ae9 + a8d2fee commit 8bc013a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/premailer/adapter/nokogiri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def to_inline_css
@processed_doc = doc
if is_xhtml?
# we don't want to encode carriage returns
@processed_doc.to_xhtml(:encoding => nil).gsub(/&\#(xD|13);/i, "\r")
@processed_doc.to_xhtml(encoding:@options[:output_encoding]).gsub(/&\#(xD|13);/i, "\r")
else
@processed_doc.to_html
@processed_doc.to_html(encoding:@options[:output_encoding])
end
end

Expand Down Expand Up @@ -186,10 +186,10 @@ def load_html(input) # :nodoc:
# TODO: duplicate options
if @options[:with_html_string] or @options[:inline] or input.respond_to?(:read)
thing = input
elsif @is_local_file
elsif @is_local_file
@base_dir = File.dirname(input)
thing = File.open(input, 'r')
else
else
thing = open(input)
end

Expand Down
4 changes: 4 additions & 0 deletions lib/premailer/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
options[:line_length] = v
end

opts.on("-e", "--entities", "Output HTML entities instead of UTF-8 when using Nokogiri") do |v|
options[:output_encoding] = "US-ASCII"
end

opts.on("-d", "--io-exceptions", "Abort on I/O errors") do |v|
options[:io_exceptions] = v
end
Expand Down
1 change: 1 addition & 0 deletions lib/premailer/premailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def initialize(html, options = {})
:include_link_tags => true,
:include_style_tags => true,
:input_encoding => 'ASCII-8BIT',
:output_encoding => nil,
:replace_html_entities => false,
:adapter => Adapter.use,
}.merge(options)
Expand Down

0 comments on commit 8bc013a

Please sign in to comment.