Giter Club home page Giter Club logo

premailer's Introduction

Premailer README CI Gem Version

What is this?

For the best HTML e-mail delivery results, CSS should be inline. This is a huge pain and a simple newsletter becomes un-managable very quickly. This gem is a solution.

  • CSS styles are converted to inline style attributes
    • Checks style and link[rel=stylesheet] tags and preserves existing inline attributes
  • Relative paths are converted to absolute paths
    • Checks links in href, src and CSS url('')
  • CSS properties are checked against e-mail client capabilities
    • Based on the Email Standards Project's guides
  • A plain text version is created (optional)

Installation

gem install premailer

Example

require 'premailer'

premailer = Premailer.new('http://example.com/myfile.html', warn_level: Premailer::Warnings::SAFE)

# Write the plain-text output (must come before to_inline_css)
File.write "output.txt", premailer.to_plain_text

# Write the HTML output
File.write "output.html", premailer.to_inline_css

# Output any CSS warnings
premailer.warnings.each do |w|
  puts "#{w[:message]} (#{w[:level]}) may not render properly in #{w[:clients]}"
end

Adapters

  1. nokogiri (default)
  2. nokogiri_fast (20x speed, more memory)
  3. nokogumbo

(hpricot adapter removed, use ~>1.9.0 version if you need it)

Picking an adapter:

Premailer::Adapter.use = :nokogiri_fast

Ruby Compatibility

See .github/workflows/actions.yml for which ruby versions are tested. JRuby support is close, contributors are welcome.

Premailer-specific CSS

Premailer looks for a few CSS attributes that make working with tables a bit easier.

CSS Attribute Availability
-premailer-width Available on table, th and td elements
-premailer-height Available on table, tr, th and td elements
-premailer-cellpadding Available on table elements
-premailer-cellspacing Available on table elements
-premailer-align Available on table elements
data-premailer="ignore" Available on link and style elements. Premailer will ignore these elements entirely.

Each of these CSS declarations will be copied to appropriate element's attribute.

For example

table { -premailer-cellspacing: 5; -premailer-width: 500; }

will result in

<table cellspacing='5' width='500'>

Plain text version

Premailer can generate a plain text version of your HTML. Links and images will be inlined.

For example

<a href="https://example.com" >
  <img src="https://github.com/premailer.png" alt="Premailer Logo" />
</a>

will become

Premailer Logo ( https://example.com )

To ignore/omit a section of HTML content from the plain text version, wrap it with the following comments.

<!-- start text/html -->
<p>This will be omitted from the plain text version.</p>
<p>
  This is extremely helpful for <strong>removing email headers and footers</strong>
  that aren't needed in the text version.
</p>
<!-- end text/html -->

Configuration options

For example:

Premailer.new(
  html, # html as string
  with_html_string: true,
  drop_unmergeable_css_rules: true
)

available options

Contributions

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.

A few areas that are particularly in need of love:

  • Improved test coverage
  • Move un-repeated background images defined in CSS for Outlook

Credits and code

Thanks to all the wonderful contributors for their updates.

Thanks to Greenhood + Company for sponsoring some of the 1.5.6 updates, and to Campaign Monitor for supporting the web interface.

The source code can be found on GitHub.

Copyright by Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007-2017. See LICENSE.md for license details.

premailer's People

Contributors

aaronchi avatar akzhan avatar alexdunae avatar amclin avatar aried3r avatar bragboy avatar breckenedge avatar der-flo avatar filipkis avatar grosser avatar hoffi avatar iloveitaly avatar jberlinsky avatar jmatsuba avatar johanbrook avatar johnnyshields avatar markedmondson avatar meowsus avatar mlandauer avatar ndbroadbent avatar orien avatar podkot avatar ryanscottaudio avatar stanhu avatar tagliala avatar terryyin avatar tommycrumrine avatar twe4ked avatar will-in-wi avatar wnm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

premailer's Issues

Premailer returns no result in txt mode

Hey there, minor issue, but premailer returns nothing in txt mode if the input does not contain a valid HTML structure. It would be preferable if it simply returned the original input instead.

Broken specs in ruby 1.9.2

$ rvm use 1.9.2
Using ~/.rvm/gems/ruby-1.9.2-p180

$ rake test
(in ~/premailer)
Loaded suite ~/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
..................F....EFEFEEEF.<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=macintosh">
    <body>
    <p class="quote"> a must-read for fans.<br>
    </p>
    </body>
</head>
</html>
<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=macintosh">
    <body>
    <p class="quote"> a must-read for fans.<br>
    </p>
    </body>
</head>
</html>
.EEE..EFE.EEE

And infinite wait...

Premailer Should Not Encode Anchor Links

Premailer is now encoding anchor links; it shouldn't. Encoding anchor links causes issues with some link tracking systems. The encoded link is stored and replaced with a tracking link, and when the tracking link is clicked it makes a server redirect to the encoded link, which fails.

For example, the following link:
testing.com/index.php?pram1=one&pram2=two

...Is encoded to:
testing.com/index.php?pram1=one&amp;pram2=two

Of course this is a flaw of the tracking system as well. It should encode the links before it stores them. However, not all tracking systems do this, or are willing to update their system. To make Premailer work well for as many people as possible, it should not encode anchor links.

Plus, encoding anchor links has nothing to do with making CSS inline.

Missing closing slash for img, meta and br tags in XHTML

Using valid XHTML as input, after the premailer, minor errors are present: the <img>, <br> and <meta> are missing the closing slash.

For example:
<img src="..." width="36" height="17" alt="" />

is converted to:
<img src="..." width="36" height="17" alt="">

Inconsistent line endings

When the premailer script is run, it takes files ending in cr lf and adds an additional cr.
So it goes from:

<div class="row error">oickle</div>[CR][LF]
<span>hi</span>[CR][LF]

To:

<div style="background-color: #def; border-top: 1px solid #cde; margin: 10px -10px; padding: 5px 10px;">oickle</div>[CR]
[CR][LF]
<span>hi</span>[CR]
[CR][LF]

I was going to ignore this (because premailer is superawesome), but the SVN repo enforces consistent line endings so it has a cow.

Any way we could add a flag to stop the line ending modification? I'm not comfortable enough in ruby to not blow up ya'lls code.

CSS for anchor tag ('a') is not premailed.

Hi,

It appears that CSS on 'a' tags is not premailed...

The following input


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title></title>
      <style type="text/css">
      .email {
         color: #005078;
         font-size: 12px;
         font-family: Arial, Helvetica, sans-serif, Verdana;
         font-weight: bold;
      </style>
   </head>
   <body>
       <a href="mailto:[email protected]" class="email">[email protected]</a>
   </body>
</html>

produces:


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title></title>
      
   </head>
   <body>
       <a href="mailto:[email protected]" class="email">[email protected]</a>
   </body>
</html>

The correct result should be


<a href="mailto:[email protected]" class="email" style="color: #005078; font-size: 12px; font-family: Arial, Helvetica, sans-serif, Verdana; font-weight: bold;">[email protected]</a>

Thanks a lot,

dstj.

[using version 1.6.1]

Unable to use with local files (Ruby 1.8.7 on Windows XP)

Here's the error I receive:

E:\Ruby187\bin>premailer_plus "C:\inputfile.html" "C:\outputfile.html" -v
E:/Ruby187/lib/ruby/1.8/uri/common.rb:436:in `split': bad URI(is not URI?): C:\inputfile.html (URI::InvalidURIError)
from E:/Ruby187/lib/ruby/1.8/uri/common.rb:485:in `parse'
from E:/Ruby187/lib/ruby/gems/1.8/gems/premailer-plus-0.1.3/bin/../lib/premailer.rb:212:in `load_css_from_html!'
from E:/Ruby187/lib/ruby/gems/1.8/gems/premailer-plus-0.1.3/bin/../lib/premailer.rb:195:in `each'
from E:/Ruby187/lib/ruby/gems/1.8/gems/premailer-plus-0.1.3/bin/../lib/premailer.rb:195:in `load_css_from_html!'
from E:/Ruby187/lib/ruby/gems/1.8/gems/premailer-plus-0.1.3/bin/../lib/premailer.rb:86:in `initialize'
from E:/Ruby187/lib/ruby/gems/1.8/gems/premailer-plus-0.1.3/bin/premailer_plus:45:in `new'
from E:/Ruby187/lib/ruby/gems/1.8/gems/premailer-plus-0.1.3/bin/premailer_plus:45:in `run'
from E:/Ruby187/lib/ruby/gems/1.8/gems/premailer-plus-0.1.3/bin/premailer_plus:107
from E:/Ruby187/bin/premailer_plus:19:in `load'
from E:/Ruby187/bin/premailer_plus:19

The input file I'm using is the example used by premailer (from http://premailer.dialect.ca/tests/base.html).

Premailer now changes the XHTML tags without changing the doctype

First, let me say how great Premailer is and thank you. You have saved me countless hours!

I typically build my HTML email layouts with XHTML Transitional doctype and I have had good results. In the past Premailer had no problems and happily made my images paths absolute and my CSS inline. Life was good. Now it looks like premailer is getting more aggressive and is rewriting such tags as BR and IMG so they are not closed in XHTML. Now am getting lots of validation errors. I am not sure if this is a "feature" or a "bug". If a feature could this be made an option?

base_url bug

There seems to be a bug with base_url where it is always set to "nil". When I call:

When I call:
$ premailer http://www.google.com/ --base-url www.google.com -v

I get:
Processing in html mode with options {:remove_classes=>false, :line_length=>65, :verbose=>true, :base_url=>nil, :link_query_string=>nil}

I managed to fix this issue with the following code change (premiler/bin/premailer lines 34-36):
opts.on("-b", "--base-url STRING", String, "Base URL, useful for local files") do |v|
options[:base_url] = v
end

I'm running Mac OS 10.6.4 and Ruby:
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]

Bookmarklet Error on Live URLs

Using the bookmarklet in Firefox 3.6 on Windows XP, Premailer works great with local files (both using a local server and opening an HTML file in the browser). Because it's local, though, it doesn't convert relative URLs to absolute.

When I use the bookmarklet on a live URL, however, it doesn't quite work. I get this; http://premailer.dialect.ca/?bookmarklet=true&url=http%3A%2F%2Fsilveroakspleasanton.com%2Fautoresponder%2Findex.html&utm_source=remote_bookmarklet&utm_medium=bookmarklet&utm_campaign=Tools

Not such a big deal, but it would be cool if it worked on live URLs so that I didn't have to manually change relative links to absolute.

Thanks for the great utility, it's very useful!

Broken specs in REE

$ rvm use ree
Using ~/.rvm/gems/ree-1.8.7-2011.03

$ git checkout upstream/master
Note: checking out 'upstream/master'.
HEAD is now at 5024c1f... Don't convert links starting with percentage signs -- closes GH-51

$ rake test
(in ~/premailer)
Loaded suite ~/.rvm/gems/ree-1.8.7-2011.03/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
..................F....output error : unknown encoding ASCII-8BIT
Eoutput error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
Foutput error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
Foutput error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
Foutput error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
Foutput error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
.output error : unknown encoding ASCII-8BIT
Eoutput error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
Foutput error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
Eoutput error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT

output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT

.output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
Foutput error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
Foutput error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
Eoutput error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
Foutput error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT
.output error : unknown encoding ASCII-8BIT
~/.rvm/gems/ree-1.8.7-2011.03/gems/nokogiri-1.4.4/lib/nokogiri/xml/node.rb:617: [BUG] Segmentation fault
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10.6.0], MBARI 0x6770, Ruby Enterprise Edition 2011.03

rake aborted!
Command failed with status (): [~/.rvm/rubies/ree-1.8.7...]

(See full trace by running task with --trace)

Load inline html?

It would be really nice if there was an option to parse inline html as a string instead of reading a file. I'm loading in mailing templates from the database so having to initialize premailer from a path is an extra step

Heading Tag is Unclosed

When Premailer converts this HTML in my code:
....


<h3 "id="WAR">Writes and Resources
<table ....

it drops the closing </h3> tag:


<h3 "id="WAR">Writes and Resources
<table ....

Full Input HTMLand output HTML are available.

Text-Version Line length

Hi,

first of all, great work, i really appreciate premailer!

Here my problem:
in Version 1.6.2 the automatic line-format does not work any more. Here is the output of premailer with -v:
Processing in txt mode with options {:line_length=>65, :verbose=>true, :base_url=>nil, :link_query_string=>nil, :remove_classes=>false}

But the Text-Version doesn't contain any newlines. I reinstalled version premailer-1.5.4 and there everything workes fine.
I am working on Suse 11.2

Best regards
Andreas

tests are not passing on ruby 1.8.7-p330

Trying to fix Adapter polluting the global namespace, but the tests aren't passing. Any ideas?

  1. Failure:
    test_style_expanding(TestMisc)
    [./test/test_misc.rb:41:in test_style_expanding' ./test/test_misc.rb:37:ineach'
    ./test/test_misc.rb:37:in `test_style_expanding']:
    <"border: none; border-left: 1px solid black;"> expected to be =~
    </border: none;\Z/i>.

  2. Failure:
    test_preserving_special_characters_hpricot(TestPremailer) [./test/test_premailer.rb:50]:
    <"c\303\251dille cé & gar\303\247on garçon \303\240 à   &"> expected but was
    <"cédille cé & garçon garçon à à   &">.

54 tests, 175 assertions, 2 failures, 0 errors

Question about Warnings

Hey,

I noticed inside the client_support.yaml there is a list of unsupported elements such as form.

These do not show up in the warnings hash when I run Premailer on the following html:

<style>form { border: 1px solid black; }</style>
<form><button>test</button></form>

Is this a bug?

Thanks!

  • Chris

Now strips unsubscribe tags

I use pommo as my mailer and it uses the tag [[!unsubscribe]] to mark unsubscribe links. Premailer is now striping out these tags in both the html and text version.

exception when applied to partial html content

Perhaps from the title, you can see what this is about ;)

Currently, Premailer assumes the presence of "<head>" with at least a child in it in order for write_unmergable_css_rules() to work. If not, the following exception occurs when to_inline_css().

>> premailer.to_inline_css
NoMethodError: undefined method `after' for nil:NilClass
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/whiny_nil.rb:48:in `method_missing'
    from /Library/Ruby/Gems/1.8/gems/premailer-1.5.7/lib/premailer/premailer.rb:353:in `write_unmergable_css_rules'
    from /Library/Ruby/Gems/1.8/gems/premailer-1.5.7/lib/premailer/premailer.rb:252:in `to_inline_css'
    from (irb):22
    from :0

Can we fix/enhance it so that this great tool doesn't bail out when applying CSS to partial HTML content/snippet? As you could imagine, there are numerous occasions when such use cases arise. (Besides, clients like Gmail strips off anything inside <head> and ignores any inline <style> tags anyway.). Perhaps there can be an additional option to specify the case when the html is not a full-blown html page and therefore, the insertion of unmergable_css_style can either be omitted, or simply placed at the beginning of the rendered html string (to be left to the rendering client's discretion whether to honor or not).

Thanks!

Problem with 2 definitions of same property.

Given

<td class="special"><p>...</p></td>

this style declaration will render a border-left after running through premailer

td { border-left: 1px solid black; }
td.special { border: none; }

and this will not render a padding-left after running through premailer

td p { padding: 0; }
td.special p { padding-left: 10px; }

It's easy enough to work around, but I thought I'd mention it since it's not the expected behavior.

Specific HTML is altered and causes bad rendering

Hello,

I' using premailer 4-5 months ago and it's very good. But now I have found a possible bug.

With an specific HTML, http://www.certiseg.com/arbolweb/campanas/promocion_cursos_calendario.htm, that has incorrect HTML structure because it has a < strong > tag between < / td > and < td > then premailer close the first table tag before strong tag so the rest of HTML is not into the table and rendering incorrectly.

We are using premailer 1.5.4 in console installed with gem but if I use the online test in http://premailer.dialect.ca/ the result is good and HTML is not broken. Do you have any suggestions to solve this problem?

Can I download older version gem?

Thanks in advance, Jesús.

Feature Request: Automatically Add Width Attributes to Table Cells

In Outlook 2007+, a lot of table-based layouts break, unless you add a WIDTH attribute to the <TD> elements of the top <TR> row containing transparent spacer GIFs. The GIFs already have the width set, but for some reason in Outlook '07 you need to set it in the <TD> elements as well.

It'd be awesome if there was an option for premailer to automatically add width attributes to the first row of table cells that contained spacer GIFs.

Test Fail - Encoding Hell

$ rake test

61 tests, 127 assertions, 19 failures, 12 errors

Foutput error : unknown encoding ASCII-8BIT
output error : unknown encoding ASCII-8BIT

Why are there so many test errors?

Error when running premailer 1.6.2

On Debian Linux, I get the following error when running premailer:

bin/premailer --mode html message.html

/root/premailer-read-only/new/lib/premailer/premailer.rb:256:in to_inline_css': private methodcreate_dimensions_shorthand!' called for #CssParser::RuleSet:0xb79705b0 (NoMethodError)
from /root/premailer-read-only/new/lib/premailer/premailer.rb:225:in each' from /root/premailer-read-only/new/lib/premailer/premailer.rb:225:into_inline_css'
from bin/premailer:96


Any ideas how to fix this? Thanks.

Command Line Premailer Fails When Inside Script

I've written an automated BASH script to run a bunch of HTML files through premailer. If I run the files indivudually via premailer -v /path/to/emails/07-19-2011.html everything works fine. If I run the a script from the terminal (which executes the command previously stated; I got the exact command via set -x on the BASH script) on OS X 10.6 via bash process.bash I get the following error:

/Library/Ruby/Gems/1.8/gems/hpricot-0.8.4/lib/hpricot/parse.rb:33: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]

process.bash: line 36: 52675 Abort trap              ruby /usr/bin/premailer -v $emailFile

I've only recently been learning ruby, so I'm definitely no expert, and this problem has truly stumped me. Any help would be much appreciated!

Segmentation fault in hpricot 0.8.3 executing from Apache-PHP

Hello,

I'm really new in ruby but I need to use the premailer ruby
library/binary. I'd like excuting this binary for PHP.

I have installed latest ruby version in debian and then I have installed
libraries through gem. When I execute command in console with user root
or user www-data it's fine.

The problem is that when I call to ruby binary from PHP-Apache (exec,
system, shell_exec) ruby throws a segmentation fault in hpricot library.

Ruby version 1.9.2p0
Rubygems version 1.3.7
Hpricot version is 0.8.3
Premailer version 1.6.2

This is the error:

/usr/local/lib/ruby/gems/1.9.1/gems/hpricot-0.8.3/lib/hpricot/parse.rb:33:
[BUG] Segmentation fault
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]

-- control frame ----------
c:0010 p:---- s:0046 b:0046 l:000045 d:000045 CFUNC :scan
c:0009 p:0074 s:0041 b:0041 l:000040 d:000040 METHOD
/usr/local/lib/ruby/gems/1.9.1/gems/hpricot-0.8.3/lib/hpricot/parse.rb:33
c:0008 p:0030 s:0034 b:0034 l:000033 d:000033 METHOD
/usr/local/lib/ruby/gems/1.9.1/gems/hpricot-0.8.3/lib/hpricot/parse.rb:4
c:0007 p:0123 s:0028 b:0028 l:000027 d:000027 METHOD
/usr/local/lib/ruby/gems/1.9.1/gems/premailer-1.6.2/lib/premailer/premailer.rb:292
c:0006 p:0264 s:0023 b:0023 l:000022 d:000022 METHOD
/usr/local/lib/ruby/gems/1.9.1/gems/premailer-1.6.2/lib/premailer/premailer.rb:142
c:0005 p:---- s:0018 b:0018 l:000017 d:000017 FINISH
c:0004 p:---- s:0016 b:0016 l:000015 d:000015 CFUNC :new
c:0003 p:0263 s:0011 b:0011 l:000698 d:0000d0 EVAL
/usr/local/lib/ruby/gems/1.9.1/gems/premailer-1.6.2/bin/premailer:87
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH

c:0001 p:0000 s:0002 b:0002 l:000698 d:000698 TOP

-- Ruby level backtrace information

/usr/local/lib/ruby/gems/1.9.1/gems/premailer-1.6.2/bin/premailer:87:in
<main>' /usr/local/lib/ruby/gems/1.9.1/gems/premailer-1.6.2/bin/premailer:87:in new'
/usr/local/lib/ruby/gems/1.9.1/gems/premailer-1.6.2/lib/premailer/premailer.rb:142:in
initialize' /usr/local/lib/ruby/gems/1.9.1/gems/premailer-1.6.2/lib/premailer/premailer.rb:292:in load_html'
/usr/local/lib/ruby/gems/1.9.1/gems/hpricot-0.8.3/lib/hpricot/parse.rb:4:in
Hpricot' /usr/local/lib/ruby/gems/1.9.1/gems/hpricot-0.8.3/lib/hpricot/parse.rb:33:in make'
/usr/local/lib/ruby/gems/1.9.1/gems/hpricot-0.8.3/lib/hpricot/parse.rb:33:in
`scan'

-- C level backtrace information

ruby(rb_vm_bugreport+0xa9) [0x52b1a9]
ruby [0x56ea56]
ruby(rb_bug+0xb1) [0x56ebd1]
ruby [0x4b93ff]
/lib/libpthread.so.0 [0x7f9e39b6ba80]
/usr/local/lib/ruby/gems/1.9.1/gems/hpricot-0.8.3/lib/hpricot_scan.so(hpricot_scan+0x240)
[0x7f9e382fdd70]
ruby [0x51e007]
ruby [0x51f5a9]
ruby [0x524858]
ruby [0x51ad5a]
ruby(rb_class_new_instance+0x32) [0x455302]
ruby [0x51e007]
ruby [0x51f5a9]
ruby [0x524858]
ruby(rb_iseq_eval_main+0x288) [0x524bd8]
ruby [0x41a753]
ruby(ruby_run_node+0x36) [0x41c446]
ruby(main+0x4d) [0x41999d]
/lib/libc.so.6(__libc_start_main+0xe6) [0x7f9e38f601a6]
ruby [0x419889]

Thanks in advance.

Why does Premailer convert ASCII code into symbols/characters?

Premailer converts [& copy ;](without spaces) to ©, [& quot ;] to ", [& amp ;] to &.. and I can't imagine a use case where this would be helpful. I've emailed Alex about this and I believe he told me that some people want it different ways.

I don't get it - this takes a perfectly-validated email transmission, and leaves with potentially hundreds of validation errors.

It makes premailer no-longer a useful tool for us, and I imagine most people, at all.

WHO are the people that told Alex they needed premailer to behave like this? Are they a majority?

Invalid pattern match in convert_inline_links function

The line:
if tag.attributes[attribute] =~ /^({|[|<|#|mailto:|ftp:|gopher:)/i

should change to:
if tag.attributes[attribute].to_s =~ /^({|[|<|#|mailto:|ftp:|gopher:)/i

.to_s is necessary there.
Also, I added "tel:" to the pattern match list.

Command line premailer problems

Hello,

this is not a bug. Or at least, as far as I can tell. It could just as easily be my lack of experience with Ruby.

Anyhow, I'm trying to get things working via the command line. I'm using Crunchbang Statler (Debian based).
I installed everyting that is needed, I checked a gazillion (well, not really, Google doesn't really return that many results when looking for premailer documentation) websites, forums, etc, but I was not yet able to get it running.

I did:
apt-get install ruby-full ruby-dev rubygems libruby
gem install htmlentities premailer hpricot

First off, running "ruby premailer in.html out.html warnings.txt"
returns: "ruby: No such file or directory -- premailer (LoadError)"

Running: "ruby path/to/bin/premailer in.html out.html warnings.txt"
returns:
"/var/lib/gems/1.8/gems/premailer-1.7.1/lib/premailer/adapter.rb:53:in const_get': no such file to load -- premailer/adapter/hpricot (LoadError) from /var/lib/gems/1.8/gems/premailer-1.7.1/lib/premailer/adapter.rb:53:infind'
from /var/lib/gems/1.8/gems/premailer-1.7.1/lib/premailer/adapter.rb:46:in use=' from /var/lib/gems/1.8/gems/premailer-1.7.1/lib/premailer/adapter.rb:21:inuse'
from /var/lib/gems/1.8/gems/premailer-1.7.1/lib/premailer/premailer.rb:129:in initialize' from /var/lib/gems/1.8/gems/premailer-1.7.1/bin/premailer:87:innew'
from /var/lib/gems/1.8/gems/premailer-1.7.1/bin/premailer:87"

Running "ruby /var/lib/gems/1.8/gems/premailer-1.7.1/lib/premailer.rb in.html out.html warnings.html"
returns: nothing (and apparently did nothing)

Same thing when running these command with the "-rubygems" operator.

"gem list" returns:
*** LOCAL GEMS ***
css_parser (1.1.9)
hpricot (0.8.4)
htmlentities (4.3.0)
premailer (1.7.1)

"gem env" returns:
RubyGems Environment:

  • RUBYGEMS VERSION: 1.3.7
  • RUBY VERSION: 1.8.7 (2010-08-16 patchlevel 302) [i486-linux]
  • INSTALLATION DIRECTORY: /var/lib/gems/1.8
  • RUBY EXECUTABLE: /usr/bin/ruby1.8
  • EXECUTABLE DIRECTORY: /var/lib/gems/1.8/bin
  • RUBYGEMS PLATFORMS:
    • ruby
    • x86-linux
  • GEM PATHS:
    • /var/lib/gems/1.8
    • /home/maarten/.gem/ruby/1.8
  • GEM CONFIGURATION:
    • :update_sources => true
    • :verbose => true
    • :benchmark => false
    • :backtrace => false
    • :bulk_threshold => 1000
    • :sources => ["http://rubygems.org/", "http://gemcutter.org", "http://gems.github.com"]
  • REMOTE SOURCES:

I'm kinda stumped here...

Kind regards, and thanks in advance!
Maarten

Trouble getting the thing installed

I'm pretty new/ignorant of ruby, but I would very much like to use the premailer script to do the css attribute thing from the commandline. I followed your directions in the readme (on an Ubuntu 9.10 (karmic)) host, and got the following:

$ sudo gem install premailer
Building native extensions. This could take a while...
ERROR: Error installing premailer:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:1

Gem files will remain installed in /var/lib/gems/1.8/gems/hpricot-0.8.2 for inspection.
Results logged to /var/lib/gems/1.8/gems/hpricot-0.8.2/ext/fast_xs/gem_make.out

At this point, I'm lost and don't know how to proceed.

xmls duplicated?

Hi there, and first of all thanks for your nice library!

I came across the following issue: https://gist.github.com/1089280

As you can see in output, the xmlns element is duplicated, I guess thats a bug, but not sure if in premailer or nokogiri.

In addition, one more side question, just out of interest: I noticed that with 1.6.x I had the problem that premailer added display:none to a lot of elements, and I did not really understand why - now with 1.7.1 this seems to be gone, was this a known issue?

Thank you,
Christoph

premailer error - this is nowhere to be found.

Premailer Error
Oh no! An error occurred when processing .

Server says: This is nowhere to be found.

If you're so inclined, you can report the error on GitHub. Please be sure to include the URL causing the problems.

I GOT THIS ERROR MESSAGES FOR THE LAST 2 TRIES OF USING PREMAILER. I HAVE BEEN USING IT FOR LONG TIME AND ALWAYS WORKED JUST GREAT BUT AFTER SITE CHANGE I STARTED GETTING THIS MESSAGE FROM TIME TO TIME. HOW CAN I FIX IT ? THERE IS NO TIP IN TE ERROR MESSAGE.

THIS IS THE CODE I HAVE SUBMITED AND CHOOSED TO REMOVE STYLE AND LINK ELEMENTS.

<title>Bleecker Happens</title> <style type="text/css"> </style>
opalasPIC

sexta 11 | OS OPALAS | Samba Rock Soul
O balanço dos Opalas toma conta do Bleecker nessa sexta.
No repertório além das autorais, tem Tim Maia, Jorge Ben e outros mestres do sambalanço!

1h00. Entrada R$25,00 (15,00 ate 0h00)


jamPIC

sábado 12 | JAM SUBURBANA
A banda Jam Suburbana toma conta do sábado no Bleecker apresetando repertório de Funk, Soul e Brasukadas!
1h00. Entrada R$25,00 (R$18,00 até 0h00)


eventosPIC
EVENTOS | FESTAS | ANIVERSÁRIOS
Infra estrutura completa para shows, eventos, apresentações, coqueteis. Clique na imagem e veja algumas sugestões de pacotes!

BLKRlogo
Rua Inácio Pereira da Rocha, 367
11 3032-3697 / [email protected]

twitterlogofacebooklogoyoutubelogo
Siga, adicione, inscreva-se.

prevent from parsing certains url's

Some email apps uses defined strings to replace utilitary links like web version or unsubscribe link.
I need to remain this strings untouched, example:

to unsubscribe <a href="%%unsubscribe%%" >click here</a>

is converted to

to unsubscribe <a href="http://www.example.com/folder/%25%25unsubscribe%25%25" >click here</a>

is there a way to prevent this from parsing?

auto-append "target="_blank"" to links as option?

hi,

i read about using target="_blank" in E-Mailings to make sure a new page will be opend in some webmailer. Perhaps it would be helpful for some people if the great premailer could offer this as new feature?

Best regards
Andi

Unable to install gem

Trying to install via the gem on latest Ubuntu (10.10) gives:

mstevens@mstevens-desktop:~ % sudo gem install premailer
[sudo] password for mstevens:
Building native extensions. This could take a while...
ERROR: Error installing premailer:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:1

Gem files will remain installed in /var/lib/gems/1.8/gems/hpricot-0.8.3 for inspection.
Results logged to /var/lib/gems/1.8/gems/hpricot-0.8.3/ext/fast_xs/gem_make.out

Query String Appended has two ?s

Title says it all.. getting two question marks instead of one when I append query strings. I'm not including a ? in my string.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.