├── test ├── fixtures │ ├── test3-noimport.css │ ├── test-import.css │ ├── test3-import.css │ ├── client_support.html │ ├── test2.css │ ├── test3.css │ ├── test.css │ ├── test.html │ ├── test-with-folding.html │ ├── test2.html │ ├── test3.html │ └── test3-out.html ├── images │ ├── inset.jpg │ └── content_bg.jpg ├── test_helper.rb ├── test_convert_to_plain_text.rb ├── test_premailer.rb ├── speed.rb ├── test_link_resolver.rb └── test_premailer_download.rb ├── CHANGELOG ├── LICENSE ├── README ├── lib ├── html_to_plain_text.rb └── premailer.rb ├── bin └── premailer └── misc └── client_support.yaml /test/fixtures/test3-noimport.css: -------------------------------------------------------------------------------- 1 | h1 { color: #f00 !important; } 2 | -------------------------------------------------------------------------------- /test/images/inset.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloopletech/premailer/master/test/images/inset.jpg -------------------------------------------------------------------------------- /test/fixtures/test-import.css: -------------------------------------------------------------------------------- 1 | body, #container { 2 | color: #fff; 3 | background: #1c2815 none; 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/test3-import.css: -------------------------------------------------------------------------------- 1 | body, #container { 2 | color: #fff; 3 | background: #1c2815 none; 4 | } 5 | -------------------------------------------------------------------------------- /test/images/content_bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloopletech/premailer/master/test/images/content_bg.jpg -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__), '../')) 2 | require 'rubygems' 3 | require 'test/unit' 4 | require 'lib/premailer' 5 | 6 | 7 | -------------------------------------------------------------------------------- /test/fixtures/client_support.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |Test page.
9 | 10 | 11 | -------------------------------------------------------------------------------- /test/test_convert_to_plain_text.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/test_helper' 2 | require 'lib/html_to_plain_text' 3 | 4 | class PlainTextTests < Test::Unit::TestCase 5 | include HtmlToPlainText 6 | 7 | def test_unordered_lists 8 | html = %q{ 9 | 10 |rake task.
28 |
29 | rake parse url=http://example.com/ out=example.html
30 |
31 | To run Premailer off a web server (using link:../index.rhtml) you will need
32 | eRuby (http://www.modruby.net/en/index.rbx/eruby/download.html).
33 |
34 | === A few notes and caveats
35 |
36 | This script is designed for simple newsletters files--complex files can
37 | get ugly very quickly.
38 |
39 | * selectors are ignored--they are just too messy.
40 |
41 | Premailer outputs HTML in UTF-8.
42 |
43 | * CSS media selectors are ignored--all CSS is processed
44 |
45 | Take a look at the HTML test file (link:../test/test.html) and CSS test file
46 | (link:../test/test.css) to see what sort of code is intended.
47 |
48 | === Credits and code
49 |
50 | Premailer is written in Ruby. The code is and web interface can be found at
51 | http://code.dunae.ca/premailer.web/
52 |
53 | Written by Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007.
54 |
--------------------------------------------------------------------------------
/lib/html_to_plain_text.rb:
--------------------------------------------------------------------------------
1 | require 'text/reform'
2 | require 'htmlentities'
3 |
4 | # Support functions for Premailer
5 | module HtmlToPlainText
6 |
7 | # Returns the text in UTF-8 format with all HTML tags removed
8 | #
9 | # TODO:
10 | # - add support for DL, OL
11 | def convert_to_text(html, line_length, from_charset = 'UTF-8')
12 | r = Text::Reform.new(:trim => true,
13 | :squeeze => false,
14 | :break => Text::Reform.break_wrap)
15 |
16 | txt = html
17 |
18 | he = HTMLEntities.new # decode HTML entities
19 |
20 | txt = he.decode(txt)
21 |
22 | txt.gsub!(/
14 |
|
25 |
|
23 |
|
27 |
|
24 |
|