inline-css
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -12,2 +12,28 @@ 'use strict'; | ||
var tableStyleAttrMap = { | ||
'table': { | ||
'float': 'align', | ||
'background-color': 'bgcolor', | ||
'width': 'width', | ||
'height': 'height' | ||
}, | ||
'tr': { | ||
'background-color': 'bgcolor', | ||
'vertical-align': 'valign', | ||
'text-align': 'align' | ||
}, | ||
'td,th': { | ||
'background-color': 'bgcolor', | ||
'width': 'width', | ||
'height': 'height', | ||
'vertical-align': 'valign', | ||
'text-align': 'align', | ||
'white-space': 'nowrap' | ||
}, | ||
'tbody,thead,tfoot': { | ||
'vertical-align': 'valign', | ||
'text-align': 'align' | ||
} | ||
}; | ||
module.exports = function (html, css, options) { | ||
@@ -97,2 +123,9 @@ var rules = parseCSS(css), | ||
for (var i in el.styleProps) { | ||
// add !important | ||
if (typeof el.styleProps[i].selector.spec !== 'undefined') { | ||
if (el.styleProps[i].selector.spec[0] === 2) { | ||
el.styleProps[i].value = el.styleProps[i].value + ' !important'; | ||
} | ||
} | ||
style.push(el.styleProps[i].prop + ': ' + el.styleProps[i].value.replace(/["]/g, '\'') + ';'); | ||
@@ -136,2 +169,12 @@ } | ||
function applyStylesAsProps($el, styleToAttrMap) { | ||
for (var style in styleToAttrMap) { | ||
var styleVal = $el.css(style); | ||
if (styleVal != undefined) { | ||
$el.attr(styleToAttrMap[style], styleVal); | ||
$el.css(style, ''); | ||
} | ||
} | ||
} | ||
function setTableAttrs(index, el) { | ||
@@ -149,2 +192,14 @@ var $el = $(el); | ||
} | ||
for (var selector in tableStyleAttrMap){ | ||
if (selector == 'table'){ | ||
applyStylesAsProps($el, tableStyleAttrMap['table']); | ||
} else { | ||
$el.find(selector).each(function(i, childEl){ | ||
applyStylesAsProps($(childEl), tableStyleAttrMap[selector]); | ||
}); | ||
} | ||
} | ||
} | ||
@@ -151,0 +206,0 @@ |
{ | ||
"name": "inline-css", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Inline css into an html file.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# inline-css [![npm](http://img.shields.io/npm/v/inline-css.svg?style=flat)](https://badge.fury.io/js/inline-css) [![Build Status](https://travis-ci.org/jonkemp/inline-css.svg?branch=master)](https://travis-ci.org/jonkemp/inline-css) | ||
[![NPM](https://nodei.co/npm/inline-css.png?downloads=true)](https://nodei.co/npm/inline-css/) | ||
> Inline your CSS properties into the `style` attribute in an html file. Useful for emails. | ||
@@ -145,3 +147,3 @@ | ||
Type: `Boolean` | ||
Type: `Boolean` | ||
Default: `false` | ||
@@ -148,0 +150,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17252
234
155