Carnet Wiki

facteur_css_inline

Version 2 — Avril 2011 — Nicolas Hoizey

facteur utilise un vieux script pour transformer les css en css inline.

Tout n’est pas possible, les syntaxes officiellement supportées sont les suivantes :

 TAG { ... }
TAG1, TAG2, ... { ... }
TAG.class { ... }
.class { ... }
TAG:pseudo { ... }

Les éléments dans le html peuvent être stylés avec l’attribut style=« ... » à condition que la valeur utilise les doubles quotes et pas les simples quotes, pour une bonne combinaison avec les styles mis inlines.

Ne sont pas supportés les styles suivants :

- genre P UL LI { .... } or P UL LI.class { .... }
-  #divname p { ... } and <tag id="...">
- a:hover, a:visited {...} multiple class:pseudo

Je remarque que n’est pas supporté non plus :

.
uneclasse, .uneclasse atag ...
</
cadre >
Précisions de l’auteur :
-  style info should be placed in < head > section.
I believe
it shouldnt be too hard to modify to point to an external
stylesheet instead.
- pseudo-classes like < code>a:hover a:hover ...</code > can’t be inserted inline
in the html tags : they are moved to a<code a < style > <style > </code > declaration in
the <code></code body > instead. This is a limitation from html, not this script.
-  CSS definitions may be freely formatted (spaces, tabs, linefeeds...), they are converted to oneliners before inserting them inline in the html tags.
-  class definitions are processed AFTER tag definitions, thus appended inline after any existing tag styling to
preserve the normal css priority behavior.

et of course :
-  It is still up to you to check if target email clients render
your css styled templates correctly, especially webmail services
like Hotmail, in which the email becomes a sub-part of an html page,
with styles already in place.

Discussion

La détection se fait par une regexp :
-  

		preg_match_all ( "/^[ \t]*([.]?)([\w, #]+)([.:])?(\S*)\s+{([^}]+)}/mi", $this->Body , $styles);

Celle ci n’est pas valide.
C’est louche !
Il faut utiliser :
-   preg_match_all ( « /^[ \t]*([.] ?)([\w, #]+)([. :]) ?(\S*)\s+{([^]+)}/mi », $this->Body , $styles) ;