premailer 1.12.0 → 1.12.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 +14 -1
- data/lib/premailer/html_to_plain_text.rb +12 -11
- data/lib/premailer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b01f24d73b41f4214ef8ca3b2a1985fe73f52c51b08fd0556ff11b8efda5122
|
4
|
+
data.tar.gz: bc7cb36fe7064821e1ec20a529b3d1ea6f7e3f77495784bb9ce7b5983f6bea25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ba7b88207293b27f1161ba1f684646b59d7783f334dcd28b562109662873423238c20a6a5b052815f890c05d9509b718c2e341ec6f7a04671a72e7b86bf7c46
|
7
|
+
data.tar.gz: 7544784edfb822d9d9c5cba949c554e9f208edfa5748567cc5a4a0455615cad3ce0aaed8b93e93235b7dc9e1b1a71c683d87bd317750fb20462fc161ff47294c
|
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
|
|
@@ -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.
|
@@ -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/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.12.
|
4
|
+
version: 1.12.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-07-
|
11
|
+
date: 2020-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: css_parser
|