@@ -25,6 +25,9 @@ type Inliner struct {
2525 // Raw HTML
2626 html string
2727
28+ // Add obsolete attributes for older clients
29+ inlineAttributes bool
30+
2831 // Parsed HTML document
2932 doc * goquery.Document
3033
@@ -44,30 +47,16 @@ type Inliner struct {
4447// NewInliner instanciates a new Inliner
4548func NewInliner (html string ) * Inliner {
4649 return & Inliner {
47- html : html ,
48- elements : make (map [string ]* Element ),
50+ html : html ,
51+ elements : make (map [string ]* Element ),
52+ inlineAttributes : true ,
4953 }
5054}
5155
5256// Inline inlines css into html document
5357func Inline (html string ) (string , error ) {
54- return InlineWithExternalCSS (html , "" )
55- }
56-
57- // InlineWithExternalCSS Includes external css
58- func InlineWithExternalCSS (html string , css string ) (string , error ) {
5958 inliner := NewInliner (html )
60- err := inliner .parseStylesheet (css )
61- if err != nil {
62- return "" , err
63- }
64-
65- result , err := inliner .Inline ()
66- if err != nil {
67- return "" , err
68- }
69-
70- return result , nil
59+ return inliner .Inline ()
7160}
7261
7362// Inline inlines CSS and returns HTML
@@ -97,6 +86,11 @@ func (inliner *Inliner) Inline() (string, error) {
9786 return inliner .genHTML ()
9887}
9988
89+ // InlineAttributes sets if the inliner should inline attributes
90+ func (inliner * Inliner ) InlineAttributes (val bool ) {
91+ inliner .inlineAttributes = val
92+ }
93+
10094// Parses raw html
10195func (inliner * Inliner ) parseHTML () error {
10296 doc , err := goquery .NewDocumentFromReader (strings .NewReader (inliner .html ))
@@ -114,7 +108,7 @@ func (inliner *Inliner) parseStylesheets() error {
114108 var result error
115109
116110 inliner .doc .Find ("style" ).EachWithBreak (func (i int , s * goquery.Selection ) bool {
117- result = inliner .parseStylesheet (s .Text ())
111+ result = inliner .ParseStylesheet (s .Text ())
118112 if result != nil {
119113 return false
120114 }
@@ -128,7 +122,8 @@ func (inliner *Inliner) parseStylesheets() error {
128122 return result
129123}
130124
131- func (inliner * Inliner ) parseStylesheet (s string ) error {
125+ // ParseStylesheet parses a stylesheet for inlining.
126+ func (inliner * Inliner ) ParseStylesheet (s string ) error {
132127 stylesheet , err := parser .Parse (s )
133128 if err != nil {
134129 return err
@@ -188,7 +183,7 @@ func (inliner *Inliner) inlineStyleRules() error {
188183 element .elt .RemoveAttr (eltMarkerAttr )
189184
190185 // inline element
191- err := element .inline ()
186+ err := element .inline (inliner . inlineAttributes )
192187 if err != nil {
193188 return err
194189 }
0 commit comments