premailer 1.12.0 → 1.14.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -2
- data/lib/premailer/adapter/nokogiri.rb +22 -9
- data/lib/premailer/adapter/nokogiri_fast.rb +21 -6
- data/lib/premailer/adapter/nokogumbo.rb +22 -9
- data/lib/premailer/html_to_plain_text.rb +12 -11
- data/lib/premailer/premailer.rb +1 -1
- data/lib/premailer/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b0c26667a2941fae4ad03348359e5bc395d6f80bb411ea8a79a7f206e22804d
|
4
|
+
data.tar.gz: f204d04b9480c0ae14853013ee7f7aa561dce207109bfa07275331d1c6e88434
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a3ab8546bdffd65325f5f564659dcb2a8ed9d93a8060c5b5fffdc14db08e719de1902f33e1495fd83777996e198d1ea53fee54e267423d5c5ac9ddacbb81755
|
7
|
+
data.tar.gz: 3252d5e22b3f553a9d73b55bc61e1609b6172a1710893871d96abd8a94891a5e1a7e562fb2f623946bf3897f73444bbed692815c908a764dbc0f108ce989dc84
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Premailer README [![Build Status](https://travis-ci.org/premailer/premailer.
|
1
|
+
# Premailer README [![Build Status](https://travis-ci.org/premailer/premailer.svg?branch=master)](https://travis-ci.org/premailer/premailer) [![Gem Version](https://badge.fury.io/rb/premailer.svg)](https://badge.fury.io/rb/premailer)
|
2
2
|
|
3
3
|
## What is this?
|
4
4
|
|
@@ -68,7 +68,7 @@ Premailer::Adapter.use = :nokogiri_fast
|
|
68
68
|
|
69
69
|
## Ruby Compatibility
|
70
70
|
|
71
|
-
|
71
|
+
See .travis.yml for which ruby versions are tested. JRuby support is close, contributors are welcome. Checkout the latest build status on the [Travis CI dashboard](https://travis-ci.org/#!/premailer/premailer).
|
72
72
|
|
73
73
|
## Premailer-specific CSS
|
74
74
|
|
@@ -97,6 +97,19 @@ will result in
|
|
97
97
|
<table cellspacing='5' width='500'>
|
98
98
|
```
|
99
99
|
|
100
|
+
## Configuration options
|
101
|
+
|
102
|
+
The behavior of Premailer can be configured by passing options in the initializer.
|
103
|
+
|
104
|
+
For example, the following will accept HTML from a string and will exclude unmergeable css from being added to the `<head>` of the output document.
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
premailer = Premailer.new(html_string, with_html_string: true, drop_unmergeable_css_rules: true)
|
108
|
+
```
|
109
|
+
|
110
|
+
[See here for a full list of the available options](https://premailer.github.io/premailer/Premailer.html#initialize-instance_method).
|
111
|
+
|
112
|
+
|
100
113
|
## Contributions
|
101
114
|
|
102
115
|
Contributions are most welcome. Premailer was rotting away in a private SVN repository for too long and could use some TLC. Fork and patch to your heart's content. Please don't increment the version numbers, though.
|
@@ -55,9 +55,7 @@ class Premailer
|
|
55
55
|
end
|
56
56
|
|
57
57
|
# Remove script tags
|
58
|
-
if @options[:remove_scripts]
|
59
|
-
doc.search("script").remove
|
60
|
-
end
|
58
|
+
doc.search("script").remove if @options[:remove_scripts]
|
61
59
|
|
62
60
|
# Read STYLE attributes and perform folding
|
63
61
|
doc.search("*[@style]").each do |el|
|
@@ -75,18 +73,33 @@ class Premailer
|
|
75
73
|
|
76
74
|
# Duplicate CSS attributes as HTML attributes
|
77
75
|
if Premailer::RELATED_ATTRIBUTES.has_key?(el.name) && @options[:css_to_attributes]
|
78
|
-
Premailer::RELATED_ATTRIBUTES[el.name].each do |
|
79
|
-
if el[
|
80
|
-
|
81
|
-
|
76
|
+
Premailer::RELATED_ATTRIBUTES[el.name].each do |css_attr, html_attr|
|
77
|
+
if el[html_attr].nil? and not merged[css_attr].empty?
|
78
|
+
new_val = merged[css_attr].dup
|
79
|
+
|
80
|
+
# Remove url() function wrapper
|
81
|
+
new_val.gsub!(/url\(['"](.*)['"]\)/, '\1')
|
82
|
+
|
83
|
+
# Remove !important, trailing semi-colon, and leading/trailing whitespace
|
84
|
+
new_val.gsub!(/;$|\s*!important/, '').strip!
|
85
|
+
|
86
|
+
# For width and height tags, remove px units
|
87
|
+
new_val.gsub!(/(\d+)px/, '\1') if %w[width height].include?(html_attr)
|
88
|
+
|
89
|
+
# For color-related tags, convert RGB to hex if specified by options
|
90
|
+
new_val = ensure_hex(new_val) if css_attr.end_with?('color') && @options[:rgb_to_hex_attributes]
|
91
|
+
|
92
|
+
el[html_attr] = new_val
|
82
93
|
end
|
94
|
+
|
83
95
|
unless @options[:preserve_style_attribute]
|
84
96
|
merged.instance_variable_get("@declarations").tap do |declarations|
|
85
|
-
|
97
|
+
declarations.delete(css_attr)
|
86
98
|
end
|
87
99
|
end
|
88
100
|
end
|
89
101
|
end
|
102
|
+
|
90
103
|
# Collapse multiple rules into one as much as possible.
|
91
104
|
merged.create_shorthand! if @options[:create_shorthands]
|
92
105
|
|
@@ -204,7 +217,7 @@ class Premailer
|
|
204
217
|
@base_dir = File.dirname(input)
|
205
218
|
thing = File.open(input, 'r')
|
206
219
|
else
|
207
|
-
thing = open(input)
|
220
|
+
thing = URI.open(input)
|
208
221
|
end
|
209
222
|
|
210
223
|
if thing.respond_to?(:read)
|
@@ -77,18 +77,33 @@ class Premailer
|
|
77
77
|
|
78
78
|
# Duplicate CSS attributes as HTML attributes
|
79
79
|
if Premailer::RELATED_ATTRIBUTES.has_key?(el.name) && @options[:css_to_attributes]
|
80
|
-
Premailer::RELATED_ATTRIBUTES[el.name].each do |
|
81
|
-
if el[
|
82
|
-
|
83
|
-
|
80
|
+
Premailer::RELATED_ATTRIBUTES[el.name].each do |css_attr, html_attr|
|
81
|
+
if el[html_attr].nil? and not merged[css_attr].empty?
|
82
|
+
new_val = merged[css_attr].dup
|
83
|
+
|
84
|
+
# Remove url() function wrapper
|
85
|
+
new_val.gsub!(/url\(['"](.*)['"]\)/, '\1')
|
86
|
+
|
87
|
+
# Remove !important, trailing semi-colon, and leading/trailing whitespace
|
88
|
+
new_val.gsub!(/;$|\s*!important/, '').strip!
|
89
|
+
|
90
|
+
# For width and height tags, remove px units
|
91
|
+
new_val.gsub!(/(\d+)px/, '\1') if %w[width height].include?(html_attr)
|
92
|
+
|
93
|
+
# For color-related tags, convert RGB to hex if specified by options
|
94
|
+
new_val = ensure_hex(new_val) if css_attr.end_with?('color') && @options[:rgb_to_hex_attributes]
|
95
|
+
|
96
|
+
el[html_attr] = new_val
|
84
97
|
end
|
98
|
+
|
85
99
|
unless @options[:preserve_style_attribute]
|
86
100
|
merged.instance_variable_get("@declarations").tap do |declarations|
|
87
|
-
|
101
|
+
declarations.delete(css_attr)
|
88
102
|
end
|
89
103
|
end
|
90
104
|
end
|
91
105
|
end
|
106
|
+
|
92
107
|
# Collapse multiple rules into one as much as possible.
|
93
108
|
merged.create_shorthand! if @options[:create_shorthands]
|
94
109
|
|
@@ -206,7 +221,7 @@ class Premailer
|
|
206
221
|
@base_dir = File.dirname(input)
|
207
222
|
thing = File.open(input, 'r')
|
208
223
|
else
|
209
|
-
thing = open(input)
|
224
|
+
thing = URI.open(input)
|
210
225
|
end
|
211
226
|
|
212
227
|
if thing.respond_to?(:read)
|
@@ -55,9 +55,7 @@ class Premailer
|
|
55
55
|
end
|
56
56
|
|
57
57
|
# Remove script tags
|
58
|
-
if @options[:remove_scripts]
|
59
|
-
doc.search("script").remove
|
60
|
-
end
|
58
|
+
doc.search("script").remove if @options[:remove_scripts]
|
61
59
|
|
62
60
|
# Read STYLE attributes and perform folding
|
63
61
|
doc.search("*[@style]").each do |el|
|
@@ -75,18 +73,33 @@ class Premailer
|
|
75
73
|
|
76
74
|
# Duplicate CSS attributes as HTML attributes
|
77
75
|
if Premailer::RELATED_ATTRIBUTES.has_key?(el.name) && @options[:css_to_attributes]
|
78
|
-
Premailer::RELATED_ATTRIBUTES[el.name].each do |
|
79
|
-
if el[
|
80
|
-
|
81
|
-
|
76
|
+
Premailer::RELATED_ATTRIBUTES[el.name].each do |css_attr, html_attr|
|
77
|
+
if el[html_attr].nil? and not merged[css_attr].empty?
|
78
|
+
new_val = merged[css_attr].dup
|
79
|
+
|
80
|
+
# Remove url() function wrapper
|
81
|
+
new_val.gsub!(/url\(['"](.*)['"]\)/, '\1')
|
82
|
+
|
83
|
+
# Remove !important, trailing semi-colon, and leading/trailing whitespace
|
84
|
+
new_val.gsub!(/;$|\s*!important/, '').strip!
|
85
|
+
|
86
|
+
# For width and height tags, remove px units
|
87
|
+
new_val.gsub!(/(\d+)px/, '\1') if %w[width height].include?(html_attr)
|
88
|
+
|
89
|
+
# For color-related tags, convert RGB to hex if specified by options
|
90
|
+
new_val = ensure_hex(new_val) if css_attr.end_with?('color') && @options[:rgb_to_hex_attributes]
|
91
|
+
|
92
|
+
el[html_attr] = new_val
|
82
93
|
end
|
94
|
+
|
83
95
|
unless @options[:preserve_style_attribute]
|
84
96
|
merged.instance_variable_get("@declarations").tap do |declarations|
|
85
|
-
|
97
|
+
declarations.delete(css_attr)
|
86
98
|
end
|
87
99
|
end
|
88
100
|
end
|
89
101
|
end
|
102
|
+
|
90
103
|
# Collapse multiple rules into one as much as possible.
|
91
104
|
merged.create_shorthand! if @options[:create_shorthands]
|
92
105
|
|
@@ -204,7 +217,7 @@ class Premailer
|
|
204
217
|
@base_dir = File.dirname(input)
|
205
218
|
thing = File.open(input, 'r')
|
206
219
|
else
|
207
|
-
thing = open(input)
|
220
|
+
thing = URI.open(input)
|
208
221
|
end
|
209
222
|
|
210
223
|
if thing.respond_to?(:read)
|
@@ -5,13 +5,14 @@ require 'htmlentities'
|
|
5
5
|
module HtmlToPlainText
|
6
6
|
|
7
7
|
# Returns the text in UTF-8 format with all HTML tags removed
|
8
|
-
#
|
9
|
-
# HTML content can be omitted from the output by surrounding it in the following comments:
|
8
|
+
#
|
9
|
+
# HTML content can be omitted from the output by surrounding it in the following comments:
|
10
10
|
#
|
11
11
|
# <!-- start text/html -->
|
12
12
|
# <!-- end text/html -->
|
13
13
|
#
|
14
14
|
# TODO: add support for DL, OL
|
15
|
+
# TODO: this is not safe and needs a real html parser to work
|
15
16
|
def convert_to_text(html, line_length = 65, from_charset = 'UTF-8')
|
16
17
|
txt = html
|
17
18
|
|
@@ -26,17 +27,17 @@ module HtmlToPlainText
|
|
26
27
|
# eg. the following formats:
|
27
28
|
# <img alt="" />
|
28
29
|
# <img alt="">
|
29
|
-
txt.gsub!(/<img
|
30
|
+
txt.gsub!(/<img[^>]+?alt="([^"]*)"[^>]*>/i, '\1')
|
30
31
|
|
31
32
|
# for img tags with '' for attribute quotes
|
32
33
|
# with or without closing tag
|
33
34
|
# eg. the following formats:
|
34
35
|
# <img alt='' />
|
35
36
|
# <img alt=''>
|
36
|
-
txt.gsub!(/<img
|
37
|
+
txt.gsub!(/<img[^>]+?alt='([^']*)'[^>]*>/i, '\1')
|
37
38
|
|
38
39
|
# remove script tags and content
|
39
|
-
txt.gsub!(/<script
|
40
|
+
txt.gsub!(/<script.*?\/script>/m, '')
|
40
41
|
|
41
42
|
# links with double quotes
|
42
43
|
txt.gsub!(/<a\s[^\n]*?href=["'](mailto:)?([^"]*)["][^>]*>(.*?)<\/a>/im) do |s|
|
@@ -75,12 +76,12 @@ module HtmlToPlainText
|
|
75
76
|
hlength = line_length if hlength > line_length
|
76
77
|
|
77
78
|
case hlevel
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
when 1 # H1, asterisks above and below
|
80
|
+
htext = ('*' * hlength) + "\n" + htext + "\n" + ('*' * hlength)
|
81
|
+
when 2 # H1, dashes above and below
|
82
|
+
htext = ('-' * hlength) + "\n" + htext + "\n" + ('-' * hlength)
|
83
|
+
else # H3-H6, dashes below
|
84
|
+
htext = htext + "\n" + ('-' * hlength)
|
84
85
|
end
|
85
86
|
|
86
87
|
"\n\n" + htext + "\n\n"
|
data/lib/premailer/premailer.rb
CHANGED
@@ -309,7 +309,7 @@ protected
|
|
309
309
|
link_uri = File.join(File.dirname(@html_file), tag.attributes['href'].to_s.sub!(@base_url.to_s, ''))
|
310
310
|
end
|
311
311
|
# if the file does not exist locally, try to grab the remote reference
|
312
|
-
unless File.
|
312
|
+
unless File.exist?(link_uri)
|
313
313
|
link_uri = Premailer.resolve_link(tag.attributes['href'].to_s, @html_file)
|
314
314
|
end
|
315
315
|
else
|
data/lib/premailer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: premailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.14.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Dunae
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: css_parser
|
@@ -218,7 +218,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
218
218
|
requirements:
|
219
219
|
- - ">="
|
220
220
|
- !ruby/object:Gem::Version
|
221
|
-
version: 2.
|
221
|
+
version: 2.5.0
|
222
222
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
223
223
|
requirements:
|
224
224
|
- - ">="
|