Coder Social home page Coder Social logo

css_parser'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.

css_parser's People

Contributors

akzhan avatar alduethadyn avatar alexdunae avatar archiloque avatar aried3r avatar dark-panda avatar dorianmariecom avatar g0dwin avatar george-gca avatar grosser avatar jdelstrother avatar johnnyshields avatar leonid-shevtsov avatar markedmondson avatar martent avatar mccuskk avatar mendable avatar miafoo avatar mkigikm avatar morten avatar mzsanford avatar ojab avatar scouttyg avatar smgt avatar stevendaniels avatar stoivo avatar tagliala avatar tylercunnion avatar viraptor avatar zapnap 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

css_parser's Issues

Clarifying versioning scheme

Hi!

I have a gem that depends on this one and I'm curious what your versioning policy is like. Do you use Semantic Versioning, or do you use something else?

It would be great to have this clarified in the README as well, so it's easy to add the proper version to one's Gemfile.

find_by_selector should return more easily navigable / parseable data structure

This code:

parser = CssParser::Parser.new
parser.load_string! 'a { color: hotpink; font-size: 13px; }'
parser.find_by_selector 'a'

Returns an array of one string:

["color: hotpink; font-size: 13px;"]

Is there a more easily navigable / parseable data structure we could return? For example, maybe something like:

[{:color=>["hotpink"], :font_size=>["13px"]}]

Fallback styles lost during parse

parser = CssParser::Parser.new
parser.load_string! 'body { background: #000; background: rgba(0,0,0,0.8); }'

puts parser.to_s #=> body { background: rgba(0,0,0,0.8); }

Setting the :import option to false on the Parser class is not working

I am receiving an URI::InvalidURIError when file that is called with the @import command within a particular stylesheet . The url that is causing the error is: http://fonts.googleapis.com/css?family=Droid+Sans:regular,bold|Droid+Serif:regular,italic,bold,bolditalic&subset=latin.

However setting the :import option on the Parser class is not making any difference. Is this something anyone else has noticed?

I am using the Class as follows:

parser = CssParser::Parser.new(:import => false, :io_exceptions => false)

Any suggestions would be much appreciated.

Circular references create stack overflow when used with Parser#load_file!

There is circular reference protection with load_uri!, but it does not protect from circular references occurring in load_file!

I encountered this when using bundler install with the --deployment flag to add the gem contents underneath the Rails root. There was a rake task we created that would use load_file to read each of the CSS files underneath the root folder which caused a stack overflow because of this.

load_uri! discards query strings

I ran into this issue with Google Web Fonts. If it should be loading http://fonts.googleapis.com/css?family=Exo|Open+Sans:300italic,400italic,600italic,700italic,300,400,600,700, it instead loads http://fonts.googleapis.com/css. Not quite the same. ;)

The issue is in parser.rb#L442. It Requests uri.path without passing uri.query. I'm not sure how you'd pass that to Net::HTTP.

For anyone else who runs into this: My workaround is to require open-uri and change load_uri!(url, opts) to add_block!(open(url).read, opts). It's not pretty, but it works for my purposes.

Media type :all handled incorrectly?

I get how media_type = :all is used as an input to various functions in this gem, but is it correct?

For example:

require 'css_parser'
include CssParser

parser = CssParser::Parser.new

css = <<-EOT
  body { margin: 0 1em; }
  @media print {
    body { color: #333; }
  }
EOT

parser.add_block!(css)

puts "All"
puts parser.find_by_selector("body", [:all])

puts "Screen"
puts parser.find_by_selector("body", [:screen])

puts "Print"
puts parser.find_by_selector("body", [:print])

I would expect the following ouptut

$ ruby test.rb 
All
margin: 0 1em;
Screen
margin: 0 1em;
Print
margin: 0 1em;
color: #333;

but I get

$ ruby test.rb 
All
margin: 0 1em;
color: #333;
Screen
Print
color: #333;

For what you are doing in this gem :any might be a better choice than :all

See Media Types

Support for @-moz-document rules

Trying to parse this stylesheet:

@-moz-document domain(google.com) {
* {color:red}
}

each_rule_set and each_selector don't return any results. I don't expect the parser to necessarily understand what this is, but some sort of indication that it sees this rule (or other at-rules) would be good.

Passing a hex color ending by 0 to border-color while having a border-top set raises an exception.

When passing a Hex color ending by 0 to border-color while also setting a border-top(as well as bottom, left and right), you get a comparison of Fixnum with nil failed exception.

This works:

td {
  border-top: 5px solid;
  border-color: #fffff1;
}

This blows up :

td {
  border-top: 5px solid;
  border-color: #fffff0;
}

Using border-top-color instead of border-color works :

td {
  border-top: 5px solid;
  border-top-color: #fffff0;
}

Premailer performance with compressed/minified CSS files

Hi,

Some weeks ago I started having performance problems in my production environment (Heroku) when sending emails with premailer - even using delayed job. Under development environment everything was running fine. My CSS is big, with Bootstrap inside it, and yes, I'm using Bootstrap to add some styles to my email messages.

I started debugging it and, after several tests, I was able to fix the problem using a non-compressed version of my application.css to send emails. This new file, called application-non-compressed.css has the same number of selectors then the original one, the only difference is that the non-compressed version was generate with "config.assets.compress = false" and was not minified.

Heroku delayed job / worker log:

  • Compressed CSS: Class#deliver completed after 194.4798
  • Non-Compressed CSS: Class#deliver completed after 5.2357

Is there any issue with premailer and big compressed CSS files?

Thanks.

Is there a way to check if a CSS has a valid format?

Hello,

I can't find in the parser docs if I can use it to test that a CSS is valid or not.

For example:
It would return false for this:

"body { color: white; }
p {laksdfja
"

And true for this:
"body {color: white; }
p {float: left; }
"

Thanks,
Ernesto

"@import url" command make CssParser::RemoteFileError: CssParser::RemoteFileError

strings at begin of css file

@import url(http://fonts.googleapis.com/css?family=Abel|Allura);
@import url(http://fonts.googleapis.com/css?family=Oswald:400,300);

versions:
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-linux]
css_parser (1.3.4)

irb(main):013:0> incss = CssParser::Parser.new
=> #false, :import=>true, :io_exceptions=>true}, @rules=[], @loaded_uris=[], @blocks=[], @folded_declaration_cache={}, @css_source="", @css_rules=[], @css_warnings=[]>

irb(main):014:0> incss.load_uri! '/tmp/040523868533654style.css'
CssParser::RemoteFileError: CssParser::RemoteFileError
  from /home/user/.gem/ruby/2.0.0/gems/css_parser-1.3.4/lib/css_parser/parser.rb:470:in `rescue in read_remote_file'
  from /home/user/.gem/ruby/2.0.0/gems/css_parser-1.3.4/lib/css_parser/parser.rb:423:in `read_remote_file'
  from /home/user/.gem/ruby/2.0.0/gems/css_parser-1.3.4/lib/css_parser/parser.rb:354:in `load_uri!'
  from /home/user/.gem/ruby/2.0.0/gems/css_parser-1.3.4/lib/css_parser/parser.rb:138:in `block in add_block!'
  from /home/user/.gem/ruby/2.0.0/gems/css_parser-1.3.4/lib/css_parser/parser.rb:122:in `each'
  from /home/user/.gem/ruby/2.0.0/gems/css_parser-1.3.4/lib/css_parser/parser.rb:122:in `add_block!'
  from /home/user/.gem/ruby/2.0.0/gems/css_parser-1.3.4/lib/css_parser/parser.rb:356:in `load_uri!'
  from (irb):14
  from /usr/bin/irb:12:in `'

Incorrect specificity handling

CssParser.calculate_specificity("body>#content~.data a[href|=foo] img:hover, p:nth-child(2*n)")
=> 124

This should return 144 (100 for #content, 10 for .data, 10 for [href], 10 for :hover, 10 for :nth-child, 1 for body, 1 for a, 1 for img, 1 for p)

load_.*! confused by invalid comments

I get that this is probably an edge case, but it is one I ran into parsing css files embedded in ePubs.

When the css contains mismatched comments like
*/ Some comment */

The selectors become filled with invalid content. Shouldn't load_uri! throw and exception in this case?

Changelog entry for 1.7

Hey! Just saw the new release, thanks! Would it be possible to have an updated CHANGELOG.md for it? :)

#<NoMethodError: undefined method `>' for nil:NilClass>

I am getting an error #<NoMethodError: undefined method >' for nil:NilClass>` while sending an email.

backtrace πŸ‘‡

/projects/rails/emailapp/vendor/ruby/2.3.0/gems/css_parser-1.3.7/lib/css_parser/rule_set.rb:453:in `split_declaration'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/css_parser-1.3.7/lib/css_parser/rule_set.rb:293:in `expand_list_style_shorthand!'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/css_parser-1.3.7/lib/css_parser/rule_set.rb:130:in `expand_shorthand!'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/premailer-1.8.6/lib/premailer/adapter/nokogiri.rb:74:in `block in to_inline_css'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/nokogiri-1.6.8.1/lib/nokogiri/xml/node_set.rb:187:in `block in each'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/nokogiri-1.6.8.1/lib/nokogiri/xml/node_set.rb:186:in `upto'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/nokogiri-1.6.8.1/lib/nokogiri/xml/node_set.rb:186:in `each'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/premailer-1.8.6/lib/premailer/adapter/nokogiri.rb:63:in `to_inline_css'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/premailer-rails-1.9.0/lib/premailer/rails/hook.rb:75:in `generate_html_part'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/premailer-rails-1.9.0/lib/premailer/rails/hook.rb:63:in `generate_alternative_part'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/premailer-rails-1.9.0/lib/premailer/rails/hook.rb:50:in `generate_html_part_replacement'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/premailer-rails-1.9.0/lib/premailer/rails/hook.rb:24:in `perform'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/premailer-rails-1.9.0/lib/premailer/rails/hook.rb:8:in `perform'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/mail-2.6.4/lib/mail/mail.rb:243:in `block in inform_interceptors'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/mail-2.6.4/lib/mail/mail.rb:242:in `each'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/mail-2.6.4/lib/mail/mail.rb:242:in `inform_interceptors'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/mail-2.6.4/lib/mail/message.rb:225:in `inform_interceptors'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/mail-2.6.4/lib/mail/message.rb:235:in `deliver'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/actionmailer-4.2.5/lib/action_mailer/message_delivery.rb:85:in `deliver_now'", 
"/projects/rails/emailapp/vendor/ruby/2.3.0/gems/actionmailer-4.2.5/lib/action_mailer/message_delivery.rb:105:in `deliver'"

Any idea what content will cause this error?

Undefined method 'find'

Correct me if I'm wrong but has the .find() method been replaced with .find_by_selector()?

If so then the README may need to be changed:

parser.find('#content')
# => 'font-size: 13px; line-height: 1.2;'```

fails to load https-based stylesheets

raises a CssParser::RemoteFileError

require 'css_parser'
p = CssParser::Parser.new
p.load_uri!('https://s3.amazonaws.com/twitter_production/a/1268699350/stylesheets/twitter-https.css')

Algorithm for generating border shorthand is incorrect when individual side border declarations exist

My client bought an email template that I'm trying to inline into our emails using premailer. The template has the following css in it

.bb {
  border-bottom: 1px solid; }

.bt,
.bb {
  border-color: #dfdfdf; }

After going through the expand_shorthand phase the declarations have properties like

"border-bottom-width" => { :value => "1px" },
"border-bottom-style" => { :value => "solid" },
"border-bottom-color" => { :value => "#dfdfdf"},
"border-top-color" => { :value => "#dfdfdf"},
"border-left-color" => { :value => "#dfdfdf"},
"border-right-color" => { :value => "#dfdfdf"}

Then it goes through the create_shorthands phase and when it runs create_dimensions_shorthand! all the border-color declarations are collapsed back into one property which is still correct.

"border-bottom-width" => { :value => "1px" },
"border-bottom-style" => { :value => "solid" },
"border-color" => { :value => "#dfdfdf"}

The problem occurs at the next phase when it runs create_border_shorthand!. It runs through the declarations checking for border-width border-style and border-color. And I do have a border color declaration so it picks that up and creates a shorthand out of it for border: #dfdfdf which then overrides the border-bottom-width and border-bottom-style declarations.

So my suggestion would be when creating border shorthands to first check if there are any individual side border styles set and if so bail out. An alternate way to fix this would be to ensure that the border-bottom-width and border-bottom-style styles are set after the border shorthand so they override the shorthand properties but I don't know if there's a good way to do that.

Do you have any thoughts?

Return line number

It would be nice to return a line number during each_selector for the current selector to use as a reference.

RuleSet#create_dimensions_shorthand! fails for certain properties

RuleSet#split_declaration raises an error:
ArgumentError: comparison of Fixnum with nil failed
for certain situations where @declarations[dest] or @declarations[src] has no :order key and the comparison > in split_declaration cannot compare an integer value to a nil value.

Please see #80.

Thank you!!

Media query should reset to :all

After a @media block, the next RuleSet’s :media_types is empty when it should be [:all].

$: << 'lib'
require 'css_parser'

css = <<CSS
body { background: red; }
@media screen {
  body { background: green; }
}
body { background: blue; }'
CSS

parser = CssParser::Parser.new
parser.load_string! css

p parser.instance_variable_get('@rules').map { |r| r[:media_types] }
# Expected: [[:all], [:screen], [:all]]
# Actual: [[:all], [:screen], []]

p parser.rules_by_media_query
# Expected: {:all=>[body { background: red; }, body { background: blue; }], :screen=>[body { background: green; }]}
# Actual: {:all=>[body { background: red; }], :screen=>[body { background: green; }]}

Can we add support for CSS3 extended color keywords?

I noticed this using premailer and premailer-rails in a rails/sass environment.

If I pass some css with the color lightyellow into css_parser, it is incorrectly parsed as yellow, due to the regex defined here and the slice! that happens here.

It looks like this regex includes the original 16 basic color keywords, the transparent keyword, and the orange extended color keyword.

Is there a reason why it doesn't include the rest of the extended color keywords?

Sample code fails to work

What steps will reproduce the problem?

  1. Run the example

What is the expected output? What do you see instead?

Expected parser to load a remote URI. After changing the call to load_file!
to load_uri!. See an error like this instead:

/Library/Ruby/Gems/1.8/gems/css_parser-0.9.0/lib/css_parser/parser.rb:322:in read_remote_file': CssParser::RemoteFileError (CssParser::RemoteFileError) from /Library/Ruby/Gems/1.8/gems/css_parser-0.9.0/lib/css_parser/parser.rb:248:inload_uri!'

Have tried with multiple valid URIs, all fail.

What version of the product are you using? On what operating system?

0.9.0 - Mac OS X Leopard

3-character hex codes should be converted to 6-character hex codes

Some browsers and email clients have trouble with 3-character hex codes:

https://litmus.com/blog/background-colors-html-email

We can help by making sure that any 3-character hex code is turned into the 6-character equivalent.

See this issue in the premailer/premailer repo: premailer/premailer#109

Colors in html emails work best as a six character hex ('#ffffff') rather than '#fff' or 'white'. See sass/sass#343 for details.

Somewhat unfortunately, sass will convert '#ffffff' to 'white'. When premailer inlines css generated by sass, it will insert 'white' instead of '#ffffff'.

sass/sass#343 goes over the sass issue. I believe sass's position is correct by saying this is something that should be fixed in premailer.

Examples of how html email can be broken by using 'white' or '#fff':

https://joevandyk.litmus.com/pub/ddace69 (email with 'white' embedded in the email, same thing happens with '#fff')
https://joevandyk.litmus.com/pub/350f5cf (exact same email, except with '#ffffff' in place of 'white')

`expand_shorthand!` overrides subsequent styles

If line-height, for example, is set after font β€” it gets overridden:

> rule_set = CssParser::RuleSet.new(nil, 'font:15px; line-height:0')
=> #<CssParser::RuleSet:0x00000000040a11e0 @declarations={"font"=>{:value=>"15px", :is_important=>false, :order=>1}, "line-height"=>{:value=>"0", :is_important=>false, :order=>2}}, @order=2, @selectors=[], @specificity=nil>
> rule_set.expand_shorthand!
=> nil
> rule_set
=> #<CssParser::RuleSet:0x00000000040a11e0
 @declarations=
  {"line-height"=>{:value=>"normal", :is_important=>false, :order=>1},
   "font-style"=>{:value=>"normal", :is_important=>false, :order=>1},
   "font-variant"=>{:value=>"normal", :is_important=>false, :order=>1},
   "font-weight"=>{:value=>"normal", :is_important=>false, :order=>1},
   "font-size"=>{:value=>"15px", :is_important=>false, :order=>1}},
 @order=2,
 @selectors=[],
 @specificity=nil>

Problem with background-image parsing

Hi

I wanted to extract gradients from my CSS but they were being cleared because they are not formatted as a url. To get all variants of the CSS gradient options I changed the split_declaration for background-image in rule_set.rb to be :-

split_declaration('background', 'background-image', value.slice!(Regexp.union(CssParser::URI_RX, /none/i, /[a-z-]gradient([a-z ,#%0-9()])$/i)))

Is there any chance you could add this or a variant?

Many Thanks

Kieran

Flunking malformed declaration tests

These two:

p { color:green; color{;color:maroon} } /* unexpected tokens { } */
p { color:red;   color{;color:maroon}; color:green } /* same with recovery */

Split css selector

I was wondering if it's possible with css_parser to split a composition of selectors.

For example, given 'span.action_item>.dropdown_menu>a'

Splitting this composition would give ['span', '.action_item', '.dropdown_menu', 'a']

My goal is to list all elementary selectors in my project.

Thank you very much for you help :)

Regexes Ignore `rem` units

I ran into this issue recently where I was using rems to size borders and the border size property was being filtered out all together because it was using rem units. If I change those declarations to another unit like em or px it's fine. Here is the relevant regex.

RuleSet should respect declaration order for Ruby Versions < 1.9

The order in which rules are declared in a CSS file is important:

h1 {
  margin: 0;
  font-size: 24px;
}

h1 {
  margin-bottom: 12px;
}

As written, the bottom margin for h1 elements is 12px; but if the two declarations were switched, the bottom margin would be 0.

Because the CssParser::RuleSet @declarations attribute is a Hash, declaration order is ignored (for Ruby version < 1.9). This commit on this branch aims to fix this. RuleSet#each_declaration now respects the declaration order.

keyframes parsing as empty declarations

css with @Keyframes rules parse as empty rule sets

css_parser (1.4.1)

css = "@keyframes shimmer {\n  0% {\n    background-position: top left;\n  }\n  100% {\n    background-position: top right;\n  }\n}"
parser = CssParser::Parser.new
parser.add_block!(css)
parser.each_rule_set do |rule_set, media_types|
  p rule_set
end

#<CssParser::RuleSet:0x007fca9ce49030 @selectors=["@keyframes shimmer"], @specificity=nil, @declarations={}, @order=0>
=> [{:media_types=>[:all], :rules=>#<CssParser::RuleSet:0x007fca9ce49030 @declarations={}, @order=0, @selectors=["@keyframes shimmer"], @specificity=nil>}]

Whats with all the Prima Donna methods?

What is the reason behind your public methods mostly ending with an exclamation mark?

This practice is usually reserved for dangerous methods, but only assuming they have a safe alternative (reference, another reference).

It feels very unnatural to write load_string! instead of just load_string...

Striping comments

Is it possible to configure the gem not to strip comments ?

1.9.3-p448 :001 > parser = CssParser::Parser.new
=>
1.9.3-p448 :002 > parser.add_block!("
1.9.3-p448 :003"> /* my css /
1.9.3-p448 :004"> body { /
hello world */
1.9.3-p448 :005"> background: yellow;
1.9.3-p448 :006"> }")
=> nil
1.9.3-p448 :007 > parser.each_rule_set do |rs|
1.9.3-p448 :008 > puts rs
1.9.3-p448 :009?> end
body { background: yellow; }
=> [{:media_types=>[:all], :rules=>body { background: yellow; }}]

iconv deprecation warning under ruby 1.9.3

Loading the gem under ruby 1.9.3 raises a deprecation warning.

$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]
$ ruby -r css_parser -e "a=1"
[...] in `require': iconv will be deprecated in the future, use String#encode instead.

[QUESTION] Same property with diferent size units

Hello, im starting to use rem instead of px, and i found that with premailer, the style inline only goes with rem units, is there a way to have the fallback to px on the inline version, since some emails like outlook don't use rem?

Exemple:
h1{
font-size:32px;
font-size:3.2rem;
}

It only uses the font-size: 3.2rem, it would be good to use both.

#305

Thanks in advance,
MΓ‘rio Silva.

[question] How to filter by media query

Hi,
I'm struggling to filter by a media type. Any help would be greatly appreciated!

CSS

@media (max-width: 767px) {
  h1 {
    font-size: 12px
  }
}

Console:
It has the media query

parser.rules_by_media_query.keys
 => [:all, :print,  :"(max-width:767px)", ...]

I can't figure out the syntax to filter by that media type though

#symbol
parser.find_by_selector("h1", :"(max-width:767px)")
 => []

#string
parser.find_by_selector("h1", "(max-width:767px)")
 => []

Patch release?

Would you mind releasing 1.2.7? Anything I can do to help?

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.