Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/revolunet/premailer
Turns CSS blocks into style attributes
https://github.com/revolunet/premailer
Last synced: 3 months ago
JSON representation
Turns CSS blocks into style attributes
- Host: GitHub
- URL: https://github.com/revolunet/premailer
- Owner: revolunet
- Fork: true (peterbe/premailer)
- Created: 2012-01-02T22:28:48.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2012-01-03T20:01:48.000Z (almost 13 years ago)
- Last Synced: 2024-07-15T15:39:33.438Z (5 months ago)
- Language: Python
- Homepage: http://www.peterbe.com/plog/premailer.py
- Size: 120 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
premailer
=========Turns CSS blocks into style attributes
--------------------------------------When you send HTML emails you can't used style tags but instead you
have to put inline `style` attributes on every element. So from this:
h1 { border:1px solid black }
p { color:red;}
p::first-letter { float:left; }
Peter
Hej
You want this:
Peter
Hej
premailer does this. It parses an HTML page, looks up `style` blocks
and parses the CSS. It then uses the `lxml.html` parser to modify the
DOM tree of the page accordingly.Turning relative URLs into absolute URLs
----------------------------------------Another thing premailer can do for you is to turn relative URLs (e.g.
"/some/page.html" into "http://www.peterbe.com/some/page.html"). It
does this to all `href` and `src` attributes that don't have a `://`
part in it. For example, turning this:Into this:
HTML attributes created additionally
------------------------------------Certain HTML attributes are also created on the HTML if the CSS
contains any ones that are easily translated into HTML attributes. For
example, if you have this CSS: `td { background-color:#eee; }` then
this is transformed into `style="background-color:#eee"` AND as an
HTML attribute `bgcolor="#eee"`.Having these extra attributes basically as a "back up" for really shit
email clients that can't even take the style attributes. A lot of
professional HTML newsletters such as Amazon's use this.